Address code review feedback

- Remove unused imports from main.py
- Add clearer documentation for extract_envelope_source_uuid
- Use Iterable[str] type hint instead of tuple

Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-01 15:16:15 +00:00
parent 8a6dbca7c9
commit 3a5bf40f41
2 changed files with 8 additions and 12 deletions

16
main.py
View File

@ -11,15 +11,6 @@ from rules import (
RuleEngine,
CommandContext,
GlobalCooldownRule,
CooldownRule,
MaxUsageRule,
MinReactionsRule,
NotUserRule,
NotSameUserRule,
TimeWindowRule,
AndRule,
OrRule,
AlwaysPassRule,
)
# Create FastAPI app
@ -178,7 +169,12 @@ async def scheduled_task(counter):
counter.string_map = {}
def extract_envelope_source_uuid(message):
"""Extract sourceUuid from the raw message (for rule engine context)."""
"""Extract sourceUuid from the raw JSON message string.
Unlike extract_source_uuid() which works on parsed envelope data,
this function parses the raw message string and extracts from envelope.
Used to get user ID for the rule engine context.
"""
message_json = json.loads(message)
return message_json.get('envelope', {}).get('sourceUuid', '')

View File

@ -8,7 +8,7 @@ logical AND/OR operations.
from abc import ABC, abstractmethod
from datetime import datetime, time, timedelta
from typing import Optional, Dict, Any, List
from typing import Optional, Dict, Any, List, Iterable
class CommandContext:
@ -307,7 +307,7 @@ class RuleEngine:
"""Set the rule for a specific command."""
self._command_rules[command] = rule
def set_command_rules(self, commands: tuple, rule: Rule):
def set_command_rules(self, commands: Iterable[str], rule: Rule):
"""Set the same rule for multiple commands."""
for command in commands:
self._command_rules[command] = rule