mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-07-04 13:43:12 +02:00
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:
parent
8a6dbca7c9
commit
3a5bf40f41
16
main.py
16
main.py
@ -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', '')
|
||||
|
||||
|
||||
4
rules.py
4
rules.py
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user