ForcePilot/backend/package/yuxi/channels/adapters/synologychat/target.py
Kris 69f4319023 feat(synologychat): 完成Synology Chat适配器的多维度优化
此提交对Synology Chat适配器进行了全面改进:
1. 新增消息去重、分布式轮询租约、bot名称配置等功能
2. 优化URL提取逻辑,自动清理尾部标点符号
3. 重构发送逻辑,提取通用重试工具函数并优化SID缓存
4. 完善文档提示与配置项,新增轮询租约类型支持
5. 修复认证API路径硬编码问题,调整交互组件提示文案
6. 增加Webhook模式下的DSM客户端兜底初始化
7. 优化导入顺序与代码结构,清理冗余空行
2026-05-13 16:15:22 +08:00

47 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Target management for Synology Chat channel.
ID normalization, validation, and format hints for user/group targeting.
"""
from __future__ import annotations
_CHANNEL_PREFIX = "synologychat:"
def normalize_target(target: str) -> str:
"""Strip channel prefix from a target identifier if present.
Handles both 'synologychat:' and 'synology-chat:' prefixes.
"""
if target.startswith("synologychat:"):
return target[len("synologychat:") :]
if target.startswith("synology-chat:"):
return target[len("synology-chat:") :]
return target
def looks_like_id(value: str) -> bool:
"""Check if a value looks like a Synology Chat user/channel ID.
Synology Chat IDs are generally pure numeric strings.
"""
return bool(value and value.isdigit())
def target_format_hint() -> str:
"""Return the expected format for target identifiers."""
return (
"Synology Chat 目标格式:\n"
"- 用户 ID纯数字字符串例如 '12345'\n"
"- 频道 ID纯数字字符串例如 '67890'\n"
"- 可通过 user_list / channel_list API 获取可用 ID\n"
"- 支持前缀格式 'synologychat:<id>'(自动剥离)\n"
)
def build_target_label(user_id: str, channel_id: str | None = None) -> str:
"""Build a human-readable label for a target."""
if channel_id:
return f"synologychat:{channel_id}:{user_id}"
return f"synologychat:{user_id}"