feat: implement /admin add @username command #73

Closed
shoko wants to merge 0 commits from fix/issue-51 into main
Owner

Summary

Implements /admin add @username and /admin remove @username commands for issue #51.

Changes

New Command

  • /admin add @username - Add a user as admin for the room
  • /admin remove @username - Remove a user from admin role

Implementation Details

  1. cmd_admin handler in commands.py:

    • Parses subcommand (add/remove) and username
    • Validates requesting user is admin
    • Resolves username to user_id by looking up bounty creators in the room
    • Calls service layer to add/remove admin
  2. _find_user_id_by_username helper:

    • Searches bounty creators in the room to find matching username
    • Returns user_id if found, None otherwise
  3. Bot registration in bot.py:

    • Added CommandHandler for "admin"
    • Added "admin" to bot command list

Error Handling

  • Non-admin trying to add/remove: ⛔ Only admins can perform this action.
  • User not found: ⛔ User @{username} not found.
  • Already admin (for add): Handled by service layer

Dependencies

  • Requires issue #43 (service layer) which is already merged
  • Uses created_by_username stored when bounties are created

Testing

# Add admin (requester must be admin)
/admin add @username
# Response: ✅ @username is now an admin.

# Remove admin (requester must be admin)
/admin remove @username
# Response: ✅ @username is no longer an admin.

# Non-admin trying
/admin add @otheruser
# Response: ⛔ Only admins can perform this action.

# User not found (username never created a bounty in room)
/admin add @nonexistent
# Response: ⛔ User @nonexistent not found.

Fixes #51

## Summary Implements `/admin add @username` and `/admin remove @username` commands for issue #51. ## Changes ### New Command - `/admin add @username` - Add a user as admin for the room - `/admin remove @username` - Remove a user from admin role ### Implementation Details 1. **cmd_admin** handler in `commands.py`: - Parses subcommand (add/remove) and username - Validates requesting user is admin - Resolves username to user_id by looking up bounty creators in the room - Calls service layer to add/remove admin 2. **_find_user_id_by_username** helper: - Searches bounty creators in the room to find matching username - Returns user_id if found, None otherwise 3. **Bot registration** in `bot.py`: - Added CommandHandler for "admin" - Added "admin" to bot command list ### Error Handling - Non-admin trying to add/remove: `⛔ Only admins can perform this action.` - User not found: `⛔ User @{username} not found.` - Already admin (for add): Handled by service layer ### Dependencies - Requires issue #43 (service layer) which is already merged - Uses `created_by_username` stored when bounties are created ## Testing ```bash # Add admin (requester must be admin) /admin add @username # Response: ✅ @username is now an admin. # Remove admin (requester must be admin) /admin remove @username # Response: ✅ @username is no longer an admin. # Non-admin trying /admin add @otheruser # Response: ⛔ Only admins can perform this action. # User not found (username never created a bounty in room) /admin add @nonexistent # Response: ⛔ User @nonexistent not found. ``` Fixes #51
shoko added 1 commit 2026-04-04 10:15:38 +02:00
- Add cmd_admin handler for /admin add|remove @username
- Add _find_user_id_by_username helper to resolve usernames from bounty creators
- Register admin command handler in bot.py
- Add 'admin' to bot command list
- Fix pre-existing duplicate due_str bug in cmd_add
- Fixes #51
shoko force-pushed fix/issue-51 from 5dee75d7d0 to e805a6428a 2026-04-04 10:19:10 +02:00 Compare
shoko closed this pull request 2026-04-04 12:18:58 +02:00

Pull request closed

Sign in to join this conversation.