1. 新增poll命令支持创建、关闭、列出投票 2. 新增审计日志记录功能 3. 优化远程附件URL安全校验逻辑 4. 修复表格匹配正则,支持包含竖线的表格分隔行 5. 新增媒体AI处理能力,支持图片描述和音频转录 6. 完善配置校验和错误处理 7. 重构文本发送逻辑,增加重试机制 8. 新增投票投票处理逻辑,支持数字快捷投票
56 lines
1.9 KiB
Python
56 lines
1.9 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},
|
|
"poll": {"description": "Manage polls: create, close, list", "requires_owner": False},
|
|
"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)
|