新增 Tlon 渠道扩展,支持在 Yuxi 平台中集成 Tlon/Urbit 去中心化通讯平台。 包含以下功能模块: - tlon_api: Tlon API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - sse_client: SSE 客户端 - outbound: 外发消息管理 - send: 消息发送 - security: 安全校验 - auth: 认证管理 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - approval: 审批流程 - channel_mgmt: 频道管理 - channel_ops: 频道操作 - contacts: 联系人管理 - discovery: 服务发现 - doctor: 健康诊断 - expose: 服务暴露 - gallery: 图库管理 - history: 历史记录 - hooks: 钩子管理 - media: 媒体资源处理 - notebook: 笔记本功能 - settings_store: 设置存储 - setup: 初始化设置 - story: 故事功能 - targets: 目标管理 - cite_parser: 引用解析 - utils: 工具函数 - types: 类型定义
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
import re
|
|
|
|
|
|
def normalize_ship(ship: str) -> str:
|
|
ship = ship.strip().lower()
|
|
if not ship:
|
|
return ""
|
|
if not ship.startswith("~"):
|
|
ship = f"~{ship}"
|
|
return ship
|
|
|
|
|
|
def is_bot_mentioned(text: str, bot_ship: str, bot_nickname: str | None = None) -> bool:
|
|
patterns = []
|
|
|
|
escaped_ship = re.escape(normalize_ship(bot_ship))
|
|
patterns.append(rf"(?<!\w){escaped_ship}(?!\w)")
|
|
|
|
patterns.append(r"(?<!\w)@all(?!\w)")
|
|
|
|
if bot_nickname:
|
|
escaped_nick = re.escape(bot_nickname)
|
|
patterns.append(rf"(?<!\w){escaped_nick}(?!\w)")
|
|
|
|
combined = "|".join(patterns)
|
|
return bool(re.search(combined, text, re.IGNORECASE))
|
|
|
|
|
|
def is_admin_mentioned(text: str) -> bool:
|
|
return bool(re.search(r"(?<!\w)@admin(?!\w)", text, re.IGNORECASE))
|
|
|
|
|
|
def extract_dm_partner_ship(whom: dict | str) -> str:
|
|
raw = ""
|
|
if isinstance(whom, str):
|
|
raw = whom
|
|
elif isinstance(whom, dict) and "ship" in whom:
|
|
raw = str(whom["ship"])
|
|
|
|
normalized = raw.strip().lstrip("~")
|
|
if re.match(r"^[a-z-]+$", normalized, re.IGNORECASE):
|
|
return f"~{normalized}"
|
|
return ""
|
|
|
|
|
|
def is_valid_ship(ship: str) -> bool:
|
|
normalized = ship.strip().lstrip("~")
|
|
return bool(re.match(r"^[a-z-]+$", normalized, re.IGNORECASE))
|
|
|
|
|
|
def is_owner(sender_ship: str, owner_ship: str | None) -> bool:
|
|
if not owner_ship:
|
|
return False
|
|
return normalize_ship(sender_ship) == normalize_ship(owner_ship)
|
|
|
|
|
|
def format_at_ud(msg_id: str) -> str:
|
|
parts = msg_id.split("/")
|
|
if len(parts) == 2:
|
|
return msg_id
|
|
return f"~zod/{msg_id}" |