From eb61278a6ecaaff91d4fff0fb4fb929e70316994 Mon Sep 17 00:00:00 2001 From: Darks Date: Sun, 13 Mar 2022 18:58:31 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20some=20bugs,=20like=20bridge-looping=20St?= =?UTF-8?q?ill=20not=20perfect,=20though=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bridge.py | 8 ++++---- irc.py | 2 +- shoutbox.py | 5 ++++- users.py | 10 +++++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bridge.py b/bridge.py index 8d4b999..909e0b6 100644 --- a/bridge.py +++ b/bridge.py @@ -5,7 +5,7 @@ from irc import IRC from shoutbox import Shoutbox from cookies import cookies from sasl import nick, password -from users import users +from users import USERS LOG_FORMAT = "%(asctime)s [%(levelname)s] <%(filename)s> %(funcName)s: %(message)s" @@ -17,9 +17,9 @@ irc = IRC('irc.planet-casio.com', 6697) shoutbox = Shoutbox(cookies) -@irc.on(lambda m: m.to[1:] in channels) +@irc.on(lambda m: m.to[1:] in channels and not m.author.endswith("[s]")) def handle_irc(m): - shoutbox.post(m.author, m.text, m.to[1:], users) + shoutbox.post(m.author, m.text, m.to[1:], USERS) @shoutbox.on(lambda m: m.channel in channels and m.author != "IRC" and not m.text.endswith("[IRC]")) @@ -28,7 +28,7 @@ def handle_shoutbox(m): shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}") -irc.start("Shoutbox[Bot]", password, nick) +irc.start("Shoutbox[darks]", password, nick) for c in channels: irc.join(f"#{c}") diff --git a/irc.py b/irc.py index d91f383..3bf6b5c 100644 --- a/irc.py +++ b/irc.py @@ -137,7 +137,7 @@ class IRC(object): class IRCMessage(object): - r = re.compile("^:(?P[\w.~|]+)(?:!(?P\S+))? PRIVMSG (?P\S+) :(?P.+)") + r = re.compile("^:(?P[\w.~|\[\]]+)(?:!(?P\S+))? PRIVMSG (?P\S+) :(?P.+)") def __init__(self, raw): match = re.search(IRCMessage.r, raw) diff --git a/shoutbox.py b/shoutbox.py index 188fd29..a953691 100644 --- a/shoutbox.py +++ b/shoutbox.py @@ -8,6 +8,7 @@ from threading import Thread from irc import IRC from sasl import nick, password +from users import USERS class Shoutbox(object): @@ -32,8 +33,8 @@ class Shoutbox(object): self.channels[channel] = m['id'] message = SBMessage(m, channel) for event, callback in self._callbacks: - # client is not known or is disconnected author = Shoutbox.normalize(message.author) + # client is not known or is disconnected if author not in self.irc_clients.keys() \ or self.irc_clients[author][0].running == False: self.irc_clients[author] = [ @@ -87,6 +88,8 @@ class Shoutbox(object): cookies=self.cookies) def normalize(pseudo): + if pseudo.lower() in [u[0].lower() for u in USERS]: + return [u[1] for u in USERS if u[0].lower() == pseudo.lower()][0] return pseudo.replace(' ', '_') diff --git a/users.py b/users.py index 50cde6a..2dad199 100644 --- a/users.py +++ b/users.py @@ -1,6 +1,10 @@ -users = [ +USERS = [ + ("Breizh_craft", "Breizh"), ("Dark Storm", "Darks"), ("Dark Storm", "Eldeberen"), - ("Breizh_craft", "Breizh"), - ("Eragon", "eragon") + ("Eragon", "eragon"), + ("FlamingKite", "FKite"), + ("FlamingKite", "FKite_"), + ("Hackcell", "Alice"), + ("Kikoodx", "KikooDX"), ]