regex efficiency wip need to look up SNO list

Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
This commit is contained in:
Pratyush Desai 2021-10-16 13:59:54 +05:30
parent 8cacf16cb9
commit 25ab2849ae

View File

@ -255,9 +255,11 @@ class SnoParser(callbacks.Plugin):
if target == irc.nick: if target == irc.nick:
# server notices CONNECT, KILL, XLINE, NICK, ACCOUNT, OPER, QUIT, # server notices CONNECT, KILL, XLINE, NICK, ACCOUNT, OPER, QUIT,
text = ircutils.stripFormatting(text) text = ircutils.stripFormatting(text)
if 'CONNECT' in text: # if 'CONNECT' in text:
connregex = "^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$" RE_CLICONN = re.compile(r"^-CONNECT- Client connected \[(.+)\] \[u\:~(.+)\] \[h\:(.+)\] \[ip\:(.+)\] \[r\:(.+)\]$")
couple = re.match(connregex, text) couple = RE_CLICONN.match(text)
# check `if couple:` ie was there a match even? if yes proceed
if couple:
nickname = couple.group(1) nickname = couple.group(1)
username = couple.group(2) username = couple.group(2)
host = couple.group(3) host = couple.group(3)
@ -271,21 +273,21 @@ class SnoParser(callbacks.Plugin):
nick_seen = self.nick_run(nickname=nickname) nick_seen = self.nick_run(nickname=nickname)
whois = self.whois_run(sourceip=ip) whois = self.whois_run(sourceip=ip)
DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} snote_dict = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen}
#repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" repl = f"\x02\x1F{snote_dict['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {snote_dict['nickname']} \x02Username:\x0F {snote_dict['username']} \x02Hostname:\x0F {snote_dict['host']} \x02IP:\x0F {snote_dict['ip']} {whois} \x02Realname:\x0F {snote_dict['realname']} \x02IPcount:\x0F {snote_dict['ipCount']} \x02NickCount:\x0F {snote_dict['nickCount']}"
repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whois} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'XLINE' in text and 'temporary' in text: # if 'XLINE' in text and 'temporary' in text:
xlineregex = "^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$" RE_XLINE = re.compile(r"^-XLINE- (.+) \[(.+)\] added temporary \((.+)\) (K-Line|D-Line) for (.+)$")
couple = re.match(xlineregex, text) couple = RE_XLINE.match(text)
if couple:
who = couple.group(1) who = couple.group(1)
who_operator = couple.group(2) who_operator = couple.group(2)
duration = couple.group(3) duration = couple.group(3)
which_line = couple.group(4) which_line = couple.group(4)
host_or_ip = couple.group(5) host_or_ip = couple.group(5)
DictFromSnotice = {'notice': 'tempban', 'who': who, 'operator': who_operator, 'duration': duration, 'type': which_line, 'target': host_or_ip} snote_dict = {'notice': 'tempban', 'who': who, 'operator': who_operator, 'duration': duration, 'type': which_line, 'target': host_or_ip}
repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']}\x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02Duration:\x0F {DictFromSnotice['duration']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['target']}" repl = f"\x02\x1FNOTICE: {snote_dict['notice']}\x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {snote_dict['who']} \x02BannedByOper:\x0F {snote_dict['operator']} \x02Duration:\x0F {snote_dict['duration']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Nick:\x0F {snote_dict['target']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
# WHY THE FUCK IS IT elif ?? # WHY THE FUCK IS IT elif ??
elif 'XLINE' in text and 'temporary' not in text and 'removed' not in text: elif 'XLINE' in text and 'temporary' not in text and 'removed' not in text:
@ -295,8 +297,8 @@ class SnoParser(callbacks.Plugin):
who_operator = couple.group(2) who_operator = couple.group(2)
which_line = couple.group(3) which_line = couple.group(3)
host_or_ip = couple.group(4) host_or_ip = couple.group(4)
DictFromSnotice = {'notice': 'Permaban', 'who': who, 'operator': who_operator, 'type': which_line, 'target': host_or_ip} snote_dict = {'notice': 'Permaban', 'who': who, 'operator': who_operator, 'type': which_line, 'target': host_or_ip}
repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {DictFromSnotice['who']} \x02BannedByOper:\x0F {DictFromSnotice['operator']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}" repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F \x11\x0303 X_X \x0F \x02BannedBy:\x0F {snote_dict['who']} \x02BannedByOper:\x0F {snote_dict['operator']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Host/IP:\x0F {snote_dict['target']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
elif 'XLINE' in text and 'removed' in text: elif 'XLINE' in text and 'removed' in text:
unxlineregex = "^-XLINE- (.+) removed (D-Line|K-Line) for (.+)$" unxlineregex = "^-XLINE- (.+) removed (D-Line|K-Line) for (.+)$"
@ -304,8 +306,8 @@ class SnoParser(callbacks.Plugin):
who = couple.group(1) who = couple.group(1)
which_line = couple.group(2) which_line = couple.group(2)
host_or_ip = couple.group(3) host_or_ip = couple.group(3)
DictFromSnotice = {'notice': 'unxline', 'who': who, 'type': which_line, 'target': host_or_ip} snote_dict = {'notice': 'unxline', 'who': who, 'type': which_line, 'target': host_or_ip}
repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303 :=D\x0F \x02UnbannedBy:\x0F {DictFromSnotice['who']} \x02XLINE type:\x0F {DictFromSnotice['type']} \x02Host/IP:\x0F {DictFromSnotice['target']}" repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F\x11\x0303 :=D\x0F \x02UnbannedBy:\x0F {snote_dict['who']} \x02XLINE type:\x0F {snote_dict['type']} \x02Host/IP:\x0F {snote_dict['target']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'KILL' in text: if 'KILL' in text:
killregex = "^-KILL- (.+) \[(.+)\] killed (\d) clients with a (KLINE|DLINE) \[(.+)\]$" killregex = "^-KILL- (.+) \[(.+)\] killed (\d) clients with a (KLINE|DLINE) \[(.+)\]$"
@ -315,22 +317,22 @@ class SnoParser(callbacks.Plugin):
clients = couple.group(3) clients = couple.group(3)
which_line = couple.group(4) which_line = couple.group(4)
nick = couple.group(5) nick = couple.group(5)
DictFromSnotice = {'notice': 'kill', 'who': who, 'operator': who_operator, "client": clients, 'type': which_line, 'nick': nick} snote_dict = {'notice': 'kill', 'who': who, 'operator': who_operator, "client": clients, 'type': which_line, 'nick': nick}
repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303☠\x0F \x02KilledBy:\x0F {DictFromSnotice['who']} \x02KilledByOper:\x0F {DictFromSnotice['operator']} \x02NumofClientsAffected:\x0F {DictFromSnotice['client']} \x02XLINE Type:\x0F {DictFromSnotice['type']} \x02Nick:\x0F {DictFromSnotice['nick']}" repl = f"\x02\x1FNOTICE: {snote_dict['notice']} \x0F\x11\x0303☠\x0F \x02KilledBy:\x0F {snote_dict['who']} \x02KilledByOper:\x0F {snote_dict['operator']} \x02NumofClientsAffected:\x0F {snote_dict['client']} \x02XLINE Type:\x0F {snote_dict['type']} \x02Nick:\x0F {snote_dict['nick']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'NICK' in text and 'changed nickname to' in text: if 'NICK' in text and 'changed nickname to' in text:
nickregex = "^-NICK- (.+) changed nickname to (.+)$" nickregex = "^-NICK- (.+) changed nickname to (.+)$"
couple = re.match(nickregex, text) couple = re.match(nickregex, text)
old_nick = couple.group(1) old_nick = couple.group(1)
new_nick = couple.group(2) new_nick = couple.group(2)
DictFromSnotice = {'notice': 'nick change', 'old_nick': old_nick, 'new_nick': new_nick} snote_dict = {'notice': 'nick change', 'old_nick': old_nick, 'new_nick': new_nick}
repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} ==> {DictFromSnotice['old_nick']} changed their nick to {DictFromSnotice['new_nick']}" repl = f"\x02\x1FNOTICE: {snote_dict['notice']} ==> {snote_dict['old_nick']} changed their nick to {snote_dict['new_nick']}"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'QUIT' in text and 'exited' in text: if 'QUIT' in text and 'exited' in text:
quitregex = "^-QUIT- (.+) exited the network$" quitregex = "^-QUIT- (.+) exited the network$"
couple = re.match(quitregex, text) couple = re.match(quitregex, text)
nick = couple.group(1) nick = couple.group(1)
DictFromSnotice = {'notice': 'quit', 'nick': nick} snote_dict = {'notice': 'quit', 'nick': nick}
repl = f"\x02\x1FNOTICE: quit nick: {nick} has exited the network" repl = f"\x02\x1FNOTICE: quit nick: {nick} has exited the network"
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if 'ACCOUNT' in text and 'registered account' in text: if 'ACCOUNT' in text and 'registered account' in text:
@ -339,7 +341,7 @@ class SnoParser(callbacks.Plugin):
hostmask = couple.group(1) hostmask = couple.group(1)
account = couple.group(2) account = couple.group(2)
ip = couple.group(3) ip = couple.group(3)
DictFromSnotice = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip} snote_dict = {'notice': 'accreg', 'hostmask': hostmask, 'account': account, 'ip': ip}
repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}" repl = f"\x02\x1FNOTICE: accreg -> [{account}] was registered by hostmask [{hostmask}] from IP {ip}"
# Trigger HS SET # Trigger HS SET
@ -351,7 +353,7 @@ class SnoParser(callbacks.Plugin):
couple = re.match(accregex, text) couple = re.match(accregex, text)
oper = couple.group(1) oper = couple.group(1)
account = couple.group(2) account = couple.group(2)
DictFromSnotice = {'notice': 'sareg', 'oper': oper, 'account': account} snote_dict = {'notice': 'sareg', 'oper': oper, 'account': account}
repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]" repl = f"\x02\x1FNOTICE: sareg -> [{account}] was registered by operator [{oper}]"
self._setvhost(irc, msg, account) self._setvhost(irc, msg, account)
@ -365,7 +367,7 @@ class SnoParser(callbacks.Plugin):
print(couple) print(couple)
DictFromSnotice = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper} snote_dict = {'notice': 'opered', 'hostmask': hostmask, 'oper': oper}
repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]." repl = f"\x02\x1FNOTICE:\x0F [{hostmask}] opered up as [{oper}]."
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
@ -375,7 +377,7 @@ class SnoParser(callbacks.Plugin):
operregex = "^-OPER- Client deopered \[(.*)\]" operregex = "^-OPER- Client deopered \[(.*)\]"
couple = re.match(operregex, text) couple = re.match(operregex, text)
account = couple.group(1) account = couple.group(1)
DictFromSnotice = {'notice': 'deopered', 'name': account} snote_dict = {'notice': 'deopered', 'name': account}
repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down." repl = f"\x02\x1FNOTICE:\x0F [{account}] opered down."
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)