ForcePilot/backend/package/yuxi/channels/adapters/urbit/targets.py
Kris 80e3f66974 refactor(urbit): 整理导入顺序并修复多处代码细节
1.  统一调整多个文件的导入排序,将TYPE_CHECKING相关导入放在正确位置
2.  修复rate_limiter中当限制数<=0时直接返回false的逻辑
3.  为message_cache新增更新消息内容的方法
4.  重构extract_graph_content支持日记类型内容提取
5.  调整@提及匹配的正则表达式,避免误匹配
6.  完善invite_manager,添加客户端和凭据支持并实现自动接受群邀请逻辑
7.  调整adapter.py中的导入顺序和初始化逻辑
8.  修复monitor中的编辑事件处理,改为异步处理并实现消息更新缓存
9.  调整datetime导入顺序,统一使用UTC在前的格式
2026-05-13 16:16:27 +08:00

43 lines
1.4 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
pass
def parse_tlon_target(target: str) -> dict[str, str]:
target = target.strip().lstrip("~")
if target.startswith("tlon:dm/"):
return {"chat_type": "direct", "peer_id": target[len("tlon:dm/") :]}
if target.startswith("dm/"):
return {"chat_type": "direct", "peer_id": target[3:]}
if target.startswith("group:chat/"):
parts = target[len("group:chat/") :].split("/")
if len(parts) >= 2:
return {"chat_type": "group", "group_name": "/".join(parts), "channel_type": "chat"}
return {"chat_type": "group", "group_name": target[len("group:chat/") :]}
if target.startswith("group:"):
return {"chat_type": "group", "group_name": target[6:]}
nest_match = target.split("/")
if len(nest_match) >= 2 and nest_match[0] in ("chat", "diary", "heap"):
return {
"chat_type": "group",
"channel_type": nest_match[0],
"group_name": "/".join(nest_match[1:]),
}
return {"chat_type": "direct", "peer_id": target}
def format_target_hint(chat_type: str, channel_id: str, host_ship: str = "") -> str:
if chat_type == "direct":
return f"dm/~{channel_id.lstrip('~')}"
host = host_ship.lstrip("~")
return f"~{host}/{channel_id} | chat/~{host}/{channel_id} | group:~{host}/{channel_id}"