1. 调整导入顺序和移除多余空行 2. 重构IRC NAMES命令的成员解析逻辑,正确剥离所有前缀 3. 更新配置schema:修改默认消息块大小为350字节,新增disableBlockStreaming配置项 4. 完善CTCP处理:新增ACTION支持,提取CTCP动作文本 5. 新增IRC线程上下文模拟器类 6. 新增SRV记录解析支持,自动解析IRC服务器域名 7. 新增多种IRC通知处理:ACCOUNT、AWAY、INVITE、CAP 8. 重构消息发送逻辑,添加熔断器和重试机制 9. 重写流式消息合并逻辑,新增智能合并缓冲 10. 扩展IRC CAP支持,新增多个常用扩展能力 11. 修复配置读取逻辑,适配新的配置结构
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
from .protocol import format_ctcp, is_ctcp_message, parse_ctcp
|
|
from .send import send_raw_line
|
|
|
|
|
|
async def handle_ctcp(
|
|
send_fn,
|
|
source_nick: str,
|
|
text: str,
|
|
) -> bool:
|
|
if not is_ctcp_message(text):
|
|
return False
|
|
|
|
command, args = parse_ctcp(text)
|
|
logger.debug(f"IRC CTCP from {source_nick}: {command} {args}")
|
|
|
|
if command == "PING":
|
|
reply = format_ctcp("PING", args)
|
|
send_raw_line(send_fn, f"NOTICE {source_nick} :{reply}")
|
|
elif command == "VERSION":
|
|
reply = format_ctcp("VERSION", "ForcePilot IRC Bot v1.0")
|
|
send_raw_line(send_fn, f"NOTICE {source_nick} :{reply}")
|
|
elif command == "TIME":
|
|
import time as _time
|
|
|
|
reply = format_ctcp("TIME", f"{_time.time():.0f}")
|
|
send_raw_line(send_fn, f"NOTICE {source_nick} :{reply}")
|
|
elif command == "CLIENTINFO":
|
|
reply = format_ctcp("CLIENTINFO", "PING VERSION TIME ACTION")
|
|
send_raw_line(send_fn, f"NOTICE {source_nick} :{reply}")
|
|
elif command == "ACTION":
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
def extract_ctcp_action(text: str) -> str | None:
|
|
if not is_ctcp_message(text):
|
|
return None
|
|
command, args = parse_ctcp(text)
|
|
if command == "ACTION":
|
|
return args
|
|
return None
|
|
|
|
|
|
def supports_ctcp() -> bool:
|
|
return True
|