ForcePilot/backend/package/yuxi/channels/adapters/imessage/commands.py
Kris 068cf70fe9 feat(imessage): 实现完整的 iMessage 适配器基础模块
新增 iMessage 通道适配器完整实现,包含:
1. 核心适配器与工具工厂导出
2. 运行时存储、反射防护、会话路由等基础组件
3. 消息信封、线程管理、回复上下文格式化
4. Tapback 表情反应处理、自定义异常体系
5. 审批按钮、联系人解析、速率限制功能
6. 文本净化、目标解析、缓存管理模块
7. 配置 schema、多账户支持、安装向导等配置模块
8. 审计日志、媒体AI处理等扩展功能
2026-05-12 00:44:44 +08:00

55 lines
1.8 KiB
Python

from __future__ import annotations
from typing import Any
def parse_command(text: str) -> dict[str, Any] | None:
"""解析控制命令。
支持的格式:/cmd <action> [args...]
返回 {"action": str, "args": list[str]} 或 None。
"""
if not text.startswith("/"):
return None
parts = text[1:].strip().split()
if not parts:
return None
action = parts[0].lower()
args = parts[1:] if len(parts) > 1 else []
return {"action": action, "args": args}
def is_authorized_for_commands(sender_handle: str, allow_list: list[str]) -> bool:
"""检查发送者是否有权限执行控制命令。"""
if "*" in allow_list:
return True
sender_clean = sender_handle.strip().replace(" ", "").lstrip("+")
for entry in allow_list:
entry_clean = entry.strip().replace(" ", "").lstrip("+")
if entry_clean == sender_clean:
return True
return False
AVAILABLE_COMMANDS = {
"status": {"description": "Show adapter status", "requires_owner": False},
"health": {"description": "Show health check result", "requires_owner": False},
"pairing": {"description": "Show pairing status", "requires_owner": False},
"approve": {"description": "Approve a pending approval request", "requires_owner": True},
"reject": {"description": "Reject a pending approval request", "requires_owner": True},
"allowlist": {"description": "Manage allowlist entries", "requires_owner": True},
"help": {"description": "Show this help message", "requires_owner": False},
}
def get_command_help(include_owner: bool = False) -> str:
lines = ["Available commands:"]
for name, info in AVAILABLE_COMMANDS.items():
if info["requires_owner"] and not include_owner:
continue
lines.append(f" /{name}{info['description']}")
return "\n".join(lines)