From 2c10e267e5821bd78094fe4bba03d000f98ed2fd Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Thu, 9 Nov 2023 15:36:34 -0600 Subject: [PATCH] Move to `handlers` for CTCPs --- bare.py | 3 --- bot.py | 38 ++------------------------------------ handlers.py | 10 +++++----- 3 files changed, 7 insertions(+), 44 deletions(-) diff --git a/bare.py b/bare.py index cc48a5e..fd4c9d4 100644 --- a/bare.py +++ b/bare.py @@ -55,9 +55,6 @@ class bot: def exit(self, message: str) -> NoReturn: ... - def CTCP(self, msg: str, sender: str = "", isRaw: bool = False) -> bool: - ... - def msg(self, msg: str, target: str) -> None: ... diff --git a/bot.py b/bot.py index 08fa6d2..5395d2b 100644 --- a/bot.py +++ b/bot.py @@ -72,7 +72,7 @@ class bot(bare.bot): elif ircmsg.startswith("PING "): self.ping(ircmsg) elif len(ircmsg.split("\x01")) == 3: - self.CTCP(ircmsg, isRaw=True) + handlers.CTCP(self, ircmsg) elif ircmsg.find("Closing Link") != -1: self.exit("Closing Link") else: @@ -108,7 +108,7 @@ class bot(bare.bot): if ircmsg.startswith("PING "): self.ping(ircmsg) elif len(ircmsg.split("\x01")) == 3: - self.CTCP(ircmsg, isRaw=True) + handlers.CTCP(self, ircmsg) elif code == 403: self.log(f"Joining {chan} failed", "WARN") if origin != "null": @@ -165,40 +165,6 @@ class bot(bare.bot): logs.log(message, self.server, "EXIT") exit(1) - def CTCP(self, msg: str, sender: str = "", isRaw: bool = False) -> bool: - if isRaw: - sender = msg.split("!", 1)[0][1:] - message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip() - kind = msg.split("\x01")[1].split(" ", 1)[0] - self.log(f'Responding to CTCP "{kind}" from {sender}') - if kind == "VERSION": - self.notice( - f"\x01VERSION FireBot {conf.__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01", - sender, - True, - ) - return True - elif kind == "USERINFO": - self.notice("\x01USERINFO FireBot (Firepup's bot)\x01", sender, True) - return True - elif kind == "SOURCE": - self.notice( - "\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", - sender, - True, - ) - return True - elif kind == "FINGER": - self.notice("\x01FINGER Firepup's bot\x01", sender, True) - return True - elif kind == "CLIENTINFO": - self.notice( - "\x01CLIENTINFO ACTION VERSION USERINFO SOURCE FINGER\x01", sender, True - ) - return True - self.log(f'Unknown CTCP "{kind}"', "WARN") - return False - def msg(self, msg: str, target: str) -> None: if not (target == "NickServ" and mfind(msg, ["IDENTIFY"], False)): self.log(f"Sending {bytes(msg).lazy_decode()} to {target}") diff --git a/handlers.py b/handlers.py index 15c29e8..8cc72f2 100644 --- a/handlers.py +++ b/handlers.py @@ -123,13 +123,13 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: ) handled = True if not handled and len(message.split("\x01")) == 3: - if not bot.CTCP(message, name): - CTCP = message.split("\x01")[1] - if CTCP == "ACTION ducks": + if not CTCP(bot, message): + kind = message.split("\x01")[1] + if kind == "ACTION ducks": bot.msg("\x01ACTION gets hit by a duck\x01", chan) - elif CTCP.startswith("ACTION ducks"): + elif kind.startswith("ACTION ducks"): bot.msg( - f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01", + f"\x01ACTION gets hit by {kind.split(' ', 2)[2]}\x01", chan, ) if chan in bot.channels and bot.channels[chan] >= bot.interval: