34 lines
935 B
Python
34 lines
935 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
|
||
|
|
SLASH_COMMAND_MAP: dict[str, str] = {
|
||
|
|
"/reset": "清除当前会话上下文,重新开始对话",
|
||
|
|
"/history": "查看当前会话的对话历史摘要",
|
||
|
|
"/context": "查看当前会话的上下文信息",
|
||
|
|
"/summary": "生成当前会话的总结",
|
||
|
|
"/help": "显示可用命令列表",
|
||
|
|
"/status": "查看 Bot 状态",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def extract_command(content: str) -> tuple[str | None, str]:
|
||
|
|
stripped = content.strip()
|
||
|
|
if not stripped.startswith("/"):
|
||
|
|
return None, content
|
||
|
|
|
||
|
|
parts = stripped.split(maxsplit=1)
|
||
|
|
command = parts[0].lower()
|
||
|
|
args = parts[1] if len(parts) > 1 else ""
|
||
|
|
|
||
|
|
if command in SLASH_COMMAND_MAP:
|
||
|
|
return command, args
|
||
|
|
|
||
|
|
return None, content
|
||
|
|
|
||
|
|
|
||
|
|
def get_command_help() -> str:
|
||
|
|
lines = ["可用命令:"]
|
||
|
|
for cmd, desc in SLASH_COMMAND_MAP.items():
|
||
|
|
lines.append(f" {cmd} - {desc}")
|
||
|
|
return "\n".join(lines)
|