新增 IRC 渠道的完整扩展实现,包括客户端连接管理、消息收发与流式处理、安全策略与配对验证、消息去重与规范化、状态监控与健康探测、配置模型与账户管理、错误处理等模块。
33 lines
952 B
Python
33 lines
952 B
Python
import re
|
|
|
|
|
|
def normalize_irc_target(target: str) -> str:
|
|
target = target.strip()
|
|
target = re.sub(r"^irc:", "", target)
|
|
target = re.sub(r"^(channel|user):", "", target)
|
|
if not re.match(r"^[^\s:@!]+$", target) and not target.startswith(("#", "&")):
|
|
target = target.split("!")[0]
|
|
return target
|
|
|
|
|
|
def is_channel_target(target: str) -> bool:
|
|
return target.startswith("#") or target.startswith("&")
|
|
|
|
|
|
def build_irc_allowlist_candidates(
|
|
nick: str,
|
|
user: str | None,
|
|
host: str | None,
|
|
allow_name_matching: bool = False,
|
|
) -> list[str]:
|
|
candidates = []
|
|
nick_lower = nick.lower()
|
|
if user and host:
|
|
candidates.append(f"{nick_lower}!{user.lower()}@{host.lower()}")
|
|
if user:
|
|
candidates.append(f"{nick_lower}!{user.lower()}")
|
|
if host:
|
|
candidates.append(f"{nick_lower}@{host.lower()}")
|
|
if allow_name_matching:
|
|
candidates.append(nick_lower)
|
|
return candidates |