"""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:'(自动剥离)\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}"