Download astrbot/core/utils/command_parser.py from qa1145/astrbbbb: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/spaces/qa1145/astrbbbb/resolve/main/astrbot/core/utils/command_parser.py
- Command line
-
hf download hf://spaces/qa1145/astrbbbb/astrbot/core/utils/command_parser.py
-
curl -L -o command_parser.py https://huggingface.co/spaces/qa1145/astrbbbb/resolve/main/astrbot/core/utils/command_parser.py
617 Bytes
| 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 | |