File size: 718 Bytes
508316a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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,
    )