mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
command_parser.py: - Add explicit type annotations for tokens list and return type config_number.py: - Handle float to int conversion explicitly - Simplify type checking logic file_extract.py: - Add type annotations and improve file extraction handling io.py: - Add type annotations for I/O operations log_pipe.py: - Implement TextIO interface for better compatibility - Add comprehensive type annotations - Add callback support and identifier logging session_waiter.py: - Clean up type annotations
24 lines
645 B
Python
24 lines
645 B
Python
import re
|
|
|
|
|
|
class CommandTokens:
|
|
def __init__(self) -> None:
|
|
self.tokens: list[str] = []
|
|
self.len = 0
|
|
|
|
def get(self, idx: int) -> str | None:
|
|
if idx >= self.len:
|
|
return None
|
|
return self.tokens[idx].strip()
|
|
|
|
|
|
class CommandParserMixin:
|
|
def parse_commands(self, message: str) -> CommandTokens:
|
|
cmd_tokens = CommandTokens()
|
|
cmd_tokens.tokens = re.split(r"\s+", message)
|
|
cmd_tokens.len = len(cmd_tokens.tokens)
|
|
return cmd_tokens
|
|
|
|
def regex_match(self, message: str, command: str) -> bool:
|
|
return re.search(command, message, re.MULTILINE) is not None
|