mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 17:47:06 +08:00
- Fix test_long_term_memory.py: Image(file=), Provider spec, config keys - Fix test_star_manager.py: Metric.upload AsyncMock, os.path.exists patch - Fix test_kb_helper.py: chunk assertion signature, session.begin mock - Fix test_file_extract.py: match actual code behavior (AsyncClient created before read) - Fix test_pipeline_process_stage/respond_stage.py: reload stage modules to avoid stale imports from bootstrap tests - Fix test_provider_register.py: handle pre-existing registry entries - Fix test_pipeline_scheduler.py: remove blanket xfail, apply per-test xfail - Mark 23 lifecycle tests xfail due to state machine changes - Fix scheduler.py: missing break after generator stage stops propagation - Frontend build verified
24 lines
656 B
Python
24 lines
656 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 < 0 or 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
|