新增 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: 类型定义
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from yuxi.channel.extensions.tlon.utils import normalize_ship, is_owner
|
|
|
|
|
|
def check_dm_allowlist(ship: str, dm_allowlist: set[str]) -> bool:
|
|
if not dm_allowlist:
|
|
return False
|
|
return normalize_ship(ship) in dm_allowlist
|
|
|
|
|
|
def check_channel_authorization(ship: str, channel_rules: dict | None,
|
|
default_authorized_ships: list[str],
|
|
owner_ship: str | None) -> bool:
|
|
if is_owner(ship, owner_ship):
|
|
return True
|
|
|
|
normalized = normalize_ship(ship)
|
|
|
|
if channel_rules:
|
|
mode = channel_rules.get("mode", "open")
|
|
if mode == "open":
|
|
return True
|
|
allowed = channel_rules.get("allowedShips", [])
|
|
allowed_normalized = {normalize_ship(s) for s in allowed}
|
|
if normalized in allowed_normalized:
|
|
return True
|
|
return False
|
|
|
|
default_set = {normalize_ship(s) for s in default_authorized_ships}
|
|
if default_set:
|
|
return normalized in default_set
|
|
|
|
return False
|
|
|
|
|
|
def check_group_invite_allowlist(ship: str,
|
|
group_invite_allowlist: set[str]) -> bool:
|
|
if not group_invite_allowlist:
|
|
return False
|
|
return normalize_ship(ship) in group_invite_allowlist
|
|
|
|
|
|
def is_ship_blocked_check(ship: str, blocked_ships: list[str]) -> bool:
|
|
return normalize_ship(ship) in {normalize_ship(s) for s in blocked_ships}
|
|
|
|
|
|
async def block_ship(api, ship: str) -> None:
|
|
await api.poke("chat", "chat-block-ship", {"ship": normalize_ship(ship)})
|
|
|
|
|
|
async def unblock_ship(api, ship: str) -> None:
|
|
await api.poke("chat", "chat-unblock-ship", {"ship": normalize_ship(ship)})
|
|
|
|
|
|
async def get_blocked_ships(api) -> list[str]:
|
|
try:
|
|
blocked = await api.scry("/chat/blocked.json")
|
|
return blocked.get("blocked", [])
|
|
except Exception:
|
|
return []
|
|
|
|
|
|
def detect_multi_user_dm_session(dm_messages: list[dict]) -> bool:
|
|
ships = set()
|
|
for msg in dm_messages:
|
|
author = msg.get("author", "")
|
|
if author:
|
|
ships.add(normalize_ship(author))
|
|
return len(ships) > 2 |