新增 Signal 渠道扩展,支持在 Yuxi 平台中集成 Signal 加密即时通讯渠道。 包含以下功能模块: - client: Signal 客户端封装 - daemon: signald 守护进程管理 - config_schema: 配置模式 - send: 消息发送 - accounts: 账户管理 - account_management: 账户综合管理 - access_policy: 访问策略 - identity: 身份管理 - profiles: 用户资料 - groups: 群组管理 - format: 消息格式转换 - normalize: 消息规范化 - dedupe: 消息去重 - monitor: 渠道状态监控 - probe: 健康探测 - sse_reconnect: SSE 重连机制
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
import re
|
|
|
|
SIGNAL_PREFIX = re.compile(r"^signal:", re.IGNORECASE)
|
|
GROUP_PREFIX = re.compile(r"^group:", re.IGNORECASE)
|
|
UUID_PREFIX = re.compile(r"^uuid:", re.IGNORECASE)
|
|
USERNAME_PREFIX = re.compile(r"^u:", re.IGNORECASE)
|
|
RECIPIENT_PATTERN = re.compile(r"^\+?\d{7,15}$")
|
|
|
|
|
|
def normalize_signal_target(raw: str) -> str | None:
|
|
if not raw:
|
|
return None
|
|
raw = raw.strip()
|
|
|
|
lowered = raw.lower()
|
|
if lowered.startswith("signal:group:"):
|
|
return "group:" + raw[len("signal:group:") :]
|
|
|
|
if lowered.startswith("signal:"):
|
|
inner = raw[len("signal:") :]
|
|
if inner.lower().startswith("group:"):
|
|
return inner
|
|
return _normalize_recipient(inner)
|
|
|
|
if lowered.startswith("group:"):
|
|
return raw
|
|
|
|
if lowered.startswith("u:") and not lowered.startswith("uuid:"):
|
|
return "username:" + raw[len("u:") :]
|
|
|
|
if lowered.startswith("username:"):
|
|
return raw
|
|
|
|
if lowered.startswith("uuid:"):
|
|
return _normalize_uuid(raw[len("uuid:") :])
|
|
|
|
if RECIPIENT_PATTERN.match(raw):
|
|
return _normalize_recipient(raw)
|
|
|
|
return raw
|
|
|
|
|
|
def parse_signal_target(raw: str) -> tuple[str, str] | None:
|
|
"""返回 (kind, value) 或 None; kind ∈ {recipient, groupId, username}"""
|
|
normalized = normalize_signal_target(raw)
|
|
if not normalized:
|
|
return None
|
|
|
|
lowered = normalized.lower()
|
|
if lowered.startswith("group:"):
|
|
return ("groupId", normalized[len("group:") :])
|
|
if lowered.startswith("username:"):
|
|
return ("username", normalized[len("username:") :])
|
|
return ("recipient", normalized)
|
|
|
|
|
|
def _normalize_recipient(value: str) -> str:
|
|
value = value.strip()
|
|
if not value.startswith("+"):
|
|
return f"+{value}"
|
|
return value
|
|
|
|
|
|
def _normalize_uuid(value: str) -> str:
|
|
return value.strip().replace("-", "").lower()
|