新增IRC协议相关的全套工具模块,包括: - 核心协议解析与CTCP处理 - 消息发送缓存与文本 sanitize - 账号配置管理与运行时状态 - 命令处理与权限控制 - 服务发现与诊断工具 - 多账号网关与配置加载
38 lines
1.1 KiB
Python
38 lines
1.1 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,
|
|
) -> None:
|
|
if not is_ctcp_message(text):
|
|
return
|
|
|
|
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")
|
|
send_raw_line(send_fn, f"NOTICE {source_nick} :{reply}")
|
|
|
|
|
|
def supports_ctcp() -> bool:
|
|
return True
|