新增 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: 类型定义
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Cite:
|
|
type: str
|
|
ship: str | None = None
|
|
group_flag: str | None = None
|
|
channel_nest: str | None = None
|
|
msg_id: str | None = None
|
|
|
|
|
|
def parse_cite(raw: str) -> Cite | None:
|
|
if not raw:
|
|
return None
|
|
|
|
if raw.startswith("~"):
|
|
parts = raw.split("/")
|
|
if len(parts) >= 2:
|
|
second = parts[1]
|
|
if second.isdigit():
|
|
return Cite(type="message", ship=parts[0], msg_id=raw)
|
|
return Cite(type="dm", ship=parts[0])
|
|
return Cite(type="ship", ship=raw)
|
|
|
|
if raw.startswith("chat/"):
|
|
parts = raw.split("/")
|
|
if len(parts) >= 3:
|
|
return Cite(
|
|
type="channel",
|
|
channel_nest=raw,
|
|
ship=parts[1],
|
|
)
|
|
|
|
if "/" in raw and raw.split("/")[0].startswith("~"):
|
|
parts = raw.split("/")
|
|
ship = parts[0]
|
|
if len(parts) >= 2:
|
|
return Cite(type="message", ship=ship, msg_id=raw)
|
|
|
|
return None
|
|
|
|
|
|
def resolve_cite_text(cite: Cite) -> str:
|
|
if cite.type == "ship":
|
|
return f"@{cite.ship}"
|
|
elif cite.type == "dm":
|
|
return f"@{cite.ship}"
|
|
elif cite.type == "channel":
|
|
return f"#{cite.channel_nest}"
|
|
elif cite.type == "message":
|
|
return f"↩ {cite.ship}"
|
|
return ""
|
|
|
|
|
|
async def resolve_all_cites(raw_cites: list[str]) -> list[dict]:
|
|
results = []
|
|
for raw in raw_cites:
|
|
cite = parse_cite(raw)
|
|
if cite:
|
|
results.append({"raw": raw, "cite": cite, "text": resolve_cite_text(cite)})
|
|
return results |