APP-Backend / Browser_Agent /messenger /command_parser.py
Luca448's picture
Savestate: Fix Dockerfile and add Browser_Agent for HF build, bump version to 1.8.334
508316a
Raw History Blame Contribute Delete
718 Bytes
# messenger/command_parser.py
from dataclasses import dataclass
ALLOWED_COMMANDS = {"/start", "/task", "/status", "/tasks", "/help", "/register"}
@dataclass
class ParsedCommand:
command: str
args: str
user_id: int
chat_id: int
is_authorized: bool
def parse_command(text: str, user_id: int, chat_id: int, allowed_user_id: int) -> ParsedCommand:
is_authorized = (user_id == allowed_user_id)
parts = text.strip().split(None, 1)
command = parts[0].lower() if parts else ""
args = parts[1] if len(parts) > 1 else ""
return ParsedCommand(
command=command,
args=args,
user_id=user_id,
chat_id=chat_id,
is_authorized=is_authorized,
)