mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-07-04 13:23:07 +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,
|
RuleEngine,
|
||||||
CommandContext,
|
CommandContext,
|
||||||
GlobalCooldownRule,
|
GlobalCooldownRule,
|
||||||
CooldownRule,
|
|
||||||
MaxUsageRule,
|
|
||||||
MinReactionsRule,
|
|
||||||
NotUserRule,
|
|
||||||
NotSameUserRule,
|
|
||||||
TimeWindowRule,
|
|
||||||
AndRule,
|
|
||||||
OrRule,
|
|
||||||
AlwaysPassRule,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create FastAPI app
|
# Create FastAPI app
|
||||||
@ -178,7 +169,12 @@ async def scheduled_task(counter):
|
|||||||
counter.string_map = {}
|
counter.string_map = {}
|
||||||
|
|
||||||
def extract_envelope_source_uuid(message):
|
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)
|
message_json = json.loads(message)
|
||||||
return message_json.get('envelope', {}).get('sourceUuid', '')
|
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 abc import ABC, abstractmethod
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import datetime, time, timedelta
|
||||||
from typing import Optional, Dict, Any, List
|
from typing import Optional, Dict, Any, List, Iterable
|
||||||
|
|
||||||
|
|
||||||
class CommandContext:
|
class CommandContext:
|
||||||
@ -307,7 +307,7 @@ class RuleEngine:
|
|||||||
"""Set the rule for a specific command."""
|
"""Set the rule for a specific command."""
|
||||||
self._command_rules[command] = rule
|
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."""
|
"""Set the same rule for multiple commands."""
|
||||||
for command in commands:
|
for command in commands:
|
||||||
self._command_rules[command] = rule
|
self._command_rules[command] = rule
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user