From 4f152c84ac6cf44a53e099e68dd9a31ee14721d7 Mon Sep 17 00:00:00 2001 From: xfnw Date: Mon, 14 Feb 2022 11:49:30 -0700 Subject: [PATCH] get hostmask from remote whois --- bam.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/bam.py b/bam.py index 6441362..0382c70 100644 --- a/bam.py +++ b/bam.py @@ -5,13 +5,14 @@ from ircrobots import Bot as BaseBot from ircrobots import Server as BaseServer from ircrobots import ConnectionParams -from secrets import OPER, NICK, NETWORK, HOST, SECONDS, MAXMSGS, JOIN +from secrets import OPER, NICK, NETWORK, HOST, SECONDS, MAXMSGS, JOIN, BADLINE, KILL, LOG class Server(BaseServer): def __init__(self, bot, name): super().__init__(bot, name) self.log={} + self.isoper=[] async def line_read(self, line): print(f"{self.name} < {line.format()}") if "on_" + line.command.lower() in dir(self): @@ -25,16 +26,40 @@ class Server(BaseServer): async def on_001(self, line): await self.send_raw(OPER) + async def on_313(self, line): + self.isoper.append(line.params[1]) + + async def on_378(self, line): + if line.params[1] in self.isoper: + self.isoper.remove(line.params[1]) + return + await self.send_raw(BADLINE.format(line.params[2].split()[3])) + await self.send_raw(KILL.format(line.params[1])) + async def on_privmsg(self, line): nick = line.hostmask.nickname if nick not in self.log: self.log[nick] = [] - self.log[nick].append([time.now()] + line.params) - if len(self.log[nick] > MAXMSGS): + self.log[nick].append([time.time()] + line.params) + if len(self.log[nick]) > MAXMSGS: self.log[nick].pop(0) + elif len(self.log[nick]) < MAXMSGS: + return - + if self.log[nick][0][0] + SECONDS <= time.time(): + self.log[nick].pop(0) + return + + for msg in self.log[nick][:-1]: + if msg[2] != line.params[1]: + return + + + await self.send(build("WHOIS",[nick,nick])) + await self.send_raw(LOG.format(nick,','.join(set([ln[1] for ln in self.log[nick]])))) + + del self.log[nick] class Bot(BaseBot):