Files
AstrBot/astrbot/core/utils/command_parser.py
LIghtJUNction 273b6777cf test: fix unit tests after master→dev merge
- 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
2026-05-08 12:17:58 +08:00

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