源码: app.rs:52-69 (SlashCommand::parse) 返回 (command, optional_arg) 或 None (不是 slash command)。
(input_text: str)
| 73 | |
| 74 | |
| 75 | def parse_slash_command(input_text: str) -> Optional[tuple[SlashCommand, Optional[str]]]: |
| 76 | """源码: app.rs:52-69 (SlashCommand::parse) |
| 77 | |
| 78 | 返回 (command, optional_arg) 或 None (不是 slash command)。 |
| 79 | """ |
| 80 | trimmed = input_text.strip() |
| 81 | if not trimmed.startswith("/"): |
| 82 | return None |
| 83 | |
| 84 | parts = trimmed[1:].split(None, 1) |
| 85 | cmd = parts[0].lower() if parts else "" |
| 86 | arg = parts[1] if len(parts) > 1 else None |
| 87 | |
| 88 | mapping = { |
| 89 | "help": SlashCommand.HELP, |
| 90 | "status": SlashCommand.STATUS, |
| 91 | "compact": SlashCommand.COMPACT, |
| 92 | "exit": SlashCommand.EXIT, |
| 93 | "quit": SlashCommand.EXIT, |
| 94 | } |
| 95 | return (mapping.get(cmd, SlashCommand.UNKNOWN), arg) |
| 96 | |
| 97 | |
| 98 | # ============================================================ |