35 lines
1019 B
Python
35 lines
1019 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
SLASH_COMMANDS: 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_COMMANDS:
|
||
|
|
return command, args
|
||
|
|
|
||
|
|
return None, content
|
||
|
|
|
||
|
|
|
||
|
|
def build_command_help_card() -> dict[str, Any]:
|
||
|
|
facts = {cmd: desc for cmd, desc in SLASH_COMMANDS.items()}
|
||
|
|
from .cards import build_info_card
|
||
|
|
|
||
|
|
return build_info_card("可用命令", facts, subtitle="发送以下命令与 Bot 交互")
|