本提交新增了全渠道SDK核心模块: 1. 异步锁、目标解析、动作调度等基础工具 2. 消息动作注册与统一调度系统 3. 测试套件与契约测试框架 4. 完整的目标解析流水线与工具函数 5. 资源依赖注入与生命周期管理
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
def normalize_target_input(raw: str) -> str:
|
|
if not raw:
|
|
return ""
|
|
cleaned = raw.strip()
|
|
if ":" in cleaned:
|
|
prefix, rest = cleaned.split(":", 1)
|
|
return f"{prefix.lower().strip()}:{rest.strip()}"
|
|
return cleaned
|
|
|
|
|
|
def detect_target_kind(raw: str, channel_chat_types: list[str] | None = None) -> str:
|
|
trimmed = raw.strip()
|
|
|
|
if trimmed.startswith("@") or trimmed.lower().startswith("user:"):
|
|
return "user"
|
|
if trimmed.startswith("#") or trimmed.lower().startswith("channel:"):
|
|
return "group"
|
|
if trimmed.lower().startswith("thread:"):
|
|
return "channel"
|
|
|
|
if channel_chat_types:
|
|
if "direct" in channel_chat_types and "group" not in channel_chat_types:
|
|
return "user"
|
|
|
|
return "group"
|
|
|
|
|
|
def looks_like_target_id(raw: str) -> bool:
|
|
trimmed = raw.strip()
|
|
core = trimmed
|
|
for prefix in ("user:", "channel:", "group:", "thread:", "@", "#"):
|
|
if core.lower().startswith(prefix):
|
|
core = core[len(prefix) :].strip()
|
|
break
|
|
|
|
if not core:
|
|
return False
|
|
|
|
if core.isdigit():
|
|
return True
|
|
|
|
if any("\u4e00" <= c <= "\u9fff" for c in core):
|
|
return False
|
|
if " " in core:
|
|
return False
|
|
|
|
if "-" in core and len(core) > 20:
|
|
return True
|
|
|
|
return False
|