ForcePilot/backend/package/yuxi/channels/adapters/irc/ctcp.py

38 lines
1.1 KiB
Python
Raw Normal View History

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