* refactor: code structure for improved readability and maintainability * style: ruff format * Update packages/astrbot/commands/provider.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/persona.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/llm.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/conversation.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * fix: improve error handling message formatting in key switching * fix: update LLM command to use safe get for provider settings * feat: implement ProcessLLMRequest class for handling LLM requests and persona injection --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
24 lines
617 B
Python
24 lines
617 B
Python
import re
|
|
|
|
|
|
class CommandTokens:
|
|
def __init__(self) -> None:
|
|
self.tokens = []
|
|
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):
|
|
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
|