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 <noreply@anthropic.com>
This commit is contained in:
+16
-4
@@ -107,6 +107,14 @@ def check_cooldown(sender: str, cmd_name: str, seconds: int = COOLDOWN_SECONDS)
|
|||||||
return 0
|
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 ====================
|
# ==================== COMMANDS ====================
|
||||||
|
|
||||||
|
|
||||||
@@ -1216,10 +1224,14 @@ async def cmd_ask(client: AsyncClient, room_id: str, sender: str, args: str):
|
|||||||
return
|
return
|
||||||
model = resolved
|
model = resolved
|
||||||
|
|
||||||
remaining = check_cooldown(sender, "ask")
|
if not is_elevated(client, room_id, sender):
|
||||||
if remaining:
|
remaining = check_cooldown(sender, "ask")
|
||||||
await send_text(client, room_id, f"Command on cooldown. Try again in {remaining}s.")
|
if remaining:
|
||||||
return
|
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)
|
question = sanitize_input(args)
|
||||||
if not question:
|
if not question:
|
||||||
|
|||||||
Reference in New Issue
Block a user