Spaces:
Paused
Paused
Download Browser_Agent/messenger/command_parser.py from Luca448/APP-Backend: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/Luca448/APP-Backend/resolve/main/Browser_Agent/messenger/command_parser.py
- Command line
-
hf download hf://spaces/Luca448/APP-Backend/Browser_Agent/messenger/command_parser.py
-
curl -L -o command_parser.py https://huggingface.co/spaces/Luca448/APP-Backend/resolve/main/Browser_Agent/messenger/command_parser.py
718 Bytes
| # messenger/command_parser.py | |
| from dataclasses import dataclass | |
| ALLOWED_COMMANDS = {"/start", "/task", "/status", "/tasks", "/help", "/register"} | |
| 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, | |
| ) | |