新增 Google Chat 对接的全套工具模块,包括: - 会话线程管理、消息解析与格式化 - Pub/Sub 消息解码、提及和命令识别 - 权限审批、目录管理和审计日志 - 消息缓存、媒体上传下载和 SSFR 防护 - 策略配置、卡片构建和流式回复支持
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)
|