From 5e9ec3a5ec2da9e28fbbb424904fa67470e7fcb7 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Sat, 4 Apr 2026 13:07:52 +0000 Subject: [PATCH] feat: add /admin command to list room admins Implement /admin command as specified in issue #50: - Lists all admin user IDs for the current room - Output format: 'Room Admins:\n- @user1\n- @user2' - Shows 'No admins configured for this room.' if none exist - Available to everyone (no permission check needed) Changes: - Add _find_username_by_user_id helper function - Update cmd_admin to support listing when called with no args - Update /help to include /admin command Closes #50 --- apps/telegram-bot/commands.py | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/telegram-bot/commands.py b/apps/telegram-bot/commands.py index 609a921..f421bbc 100644 --- a/apps/telegram-bot/commands.py +++ b/apps/telegram-bot/commands.py @@ -502,11 +502,42 @@ def _find_user_id_by_username(room_id: int, username: str) -> int | None: return None +def _find_username_by_user_id(room_id: int, user_id: int) -> str | None: + """Find username by user_id from bounty creators in the room.""" + bounties = BOUNTY_SERVICE.list_bounties(room_id) + for bounty in bounties: + if bounty.created_by_user_id == user_id: + return bounty.created_by_username + return None + + async def cmd_admin(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: args = extract_args(update.message.text) - if not args or args[0] not in ("add", "remove"): + + # Handle /admin with no subcommand (list admins) + if not args or args[0] == "list": + room_id = get_room_id(update) + admin_ids = BOUNTY_SERVICE.list_admins(room_id) + + if not admin_ids: + await update.message.reply_text("No admins configured for this room.") + return + + lines = ["Room Admins:"] + for admin_id in admin_ids: + username = _find_username_by_user_id(room_id, admin_id) + if username: + lines.append(f"- @{username}") + else: + lines.append(f"- user#{admin_id}") + + await update.message.reply_text("\n".join(lines)) + return + + if args[0] not in ("add", "remove"): await update.message.reply_text( "Usage:\n" + "/admin — list admins\n" "/admin add @username — add admin\n" "/admin remove @username — remove admin" ) @@ -565,6 +596,9 @@ async def cmd_help(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: "/show — show bounty details\n" "/timezone — get room timezone\n" "/timezone — set room timezone (admin only)\n" + "/admin — list room admins\n" + "/admin add @username — add admin (admin only)\n" + "/admin remove @username — remove admin (admin only)\n" "/start — re-initialize\n" "/help — this message", disable_web_page_preview=True,