From 66136ff2f7fa925a6a97479c3fdc391ac421bf32 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 28 Apr 2026 21:39:44 -0400 Subject: [PATCH] feat: bypass !ask cooldown for users with power level >= 50 Add is_elevated() helper that reads the room power level from the nio client store. Users at PL50+ (Nerdy Council and above) skip the cooldown check entirely. The timestamp is still recorded so cooldown applies if their power level is later reduced below 50. Co-Authored-By: Claude Sonnet 4.6 --- matrixbot/commands.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/matrixbot/commands.py b/matrixbot/commands.py index f012d0c..99df8f3 100644 --- a/matrixbot/commands.py +++ b/matrixbot/commands.py @@ -107,6 +107,14 @@ def check_cooldown(sender: str, cmd_name: str, seconds: int = COOLDOWN_SECONDS) return 0 +def is_elevated(client: AsyncClient, room_id: str, user_id: str, min_level: int = 50) -> bool: + """Return True if the user has a power level >= min_level in the room.""" + room = client.rooms.get(room_id) + if not room: + return False + return room.power_levels.get_user_level(user_id) >= min_level + + # ==================== COMMANDS ==================== @@ -1216,10 +1224,14 @@ async def cmd_ask(client: AsyncClient, room_id: str, sender: str, args: str): return model = resolved - remaining = check_cooldown(sender, "ask") - if remaining: - await send_text(client, room_id, f"Command on cooldown. Try again in {remaining}s.") - return + if not is_elevated(client, room_id, sender): + remaining = check_cooldown(sender, "ask") + if remaining: + await send_text(client, room_id, f"Command on cooldown. Try again in {remaining}s.") + return + else: + # Still record the timestamp so cooldown kicks in if they drop below PL50 + check_cooldown(sender, "ask") question = sanitize_input(args) if not question: