Move to handlers
for CTCPs
This commit is contained in:
parent
53efdfb830
commit
2c10e267e5
3 changed files with 7 additions and 44 deletions
3
bare.py
3
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:
|
||||
...
|
||||
|
||||
|
|
38
bot.py
38
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}")
|
||||
|
|
10
handlers.py
10
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:
|
||||
|
|
Loading…
Reference in a new issue