Improve CTCP logs, mark automatic quotes as "[QUOTE]"

This commit is contained in:
Firepup Sixfifty 2023-10-24 16:39:27 -05:00
parent d7f3db2204
commit 99b393a2b5

View file

@ -101,10 +101,11 @@ def sendmsg(msg, target):
ircsock.send(bytes(f"PRIVMSG {target} :{msg}\n", e)) ircsock.send(bytes(f"PRIVMSG {target} :{msg}\n", e))
def notice(msg, target): def notice(msg, target, silent: bool = False):
print( if not silent:
f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target} (NOTICE)" print(
) f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target} (NOTICE)"
)
ircsock.send(bytes(f"NOTICE {target} :{msg}\n", e)) ircsock.send(bytes(f"NOTICE {target} :{msg}\n", e))
@ -113,25 +114,28 @@ def CTCPHandler(msg: str, sender: str = "", isRaw: bool = False):
sender = msg.split("!", 1)[0][1:] sender = msg.split("!", 1)[0][1:]
message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip() message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
CTCP = msg.split("\x01")[1] CTCP = msg.split("\x01")[1]
print(f"[LOG][{server}] Responding to CTCP {CTCP} from {sender}")
if CTCP == "VERSION": if CTCP == "VERSION":
notice( notice(
f"\x01VERSION FireBot {__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01", f"\x01VERSION FireBot {__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01",
sender, sender,
True,
) )
return True return True
elif CTCP == "USERINFO": elif CTCP == "USERINFO":
notice("\x01USERINFO FireBot (Firepup's bot)\x01", sender) notice("\x01USERINFO FireBot (Firepup's bot)\x01", sender, True)
return True return True
elif CTCP == "SOURCE": elif CTCP == "SOURCE":
notice( notice(
"\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", sender "\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", sender,
True,
) )
return True return True
elif CTCP == "FINGER": elif CTCP == "FINGER":
notice(f"\x01FINGER Firepup's bot\x01", sender) notice(f"\x01FINGER Firepup's bot\x01", sender, True)
return True return True
elif CTCP == "CLIENTINFO": elif CTCP == "CLIENTINFO":
notice(f"\x01CLIENTINFO ACTION VERSION USERINFO SOURCE FINGER", sender) notice(f"\x01CLIENTINFO ACTION VERSION USERINFO SOURCE FINGER", sender, True)
return True return True
return False return False
@ -404,7 +408,7 @@ def main():
sel = decode_escapes( sel = decode_escapes(
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"') str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
) )
sendmsg(sel, chan) sendmsg(f"[QUOTE] {sel}", chan)
log.close() log.close()
else: else:
if ircmsg.find("PING") != -1: if ircmsg.find("PING") != -1: