Fix some bugs, like bridge-looping
Still not perfect, though…
This commit is contained in:
parent
4e0ccd8080
commit
eb61278a6e
|
@ -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}")
|
||||
|
||||
|
|
2
irc.py
2
irc.py
|
@ -137,7 +137,7 @@ class IRC(object):
|
|||
|
||||
|
||||
class IRCMessage(object):
|
||||
r = re.compile("^:(?P<author>[\w.~|]+)(?:!(?P<host>\S+))? PRIVMSG (?P<to>\S+) :(?P<text>.+)")
|
||||
r = re.compile("^:(?P<author>[\w.~|\[\]]+)(?:!(?P<host>\S+))? PRIVMSG (?P<to>\S+) :(?P<text>.+)")
|
||||
|
||||
def __init__(self, raw):
|
||||
match = re.search(IRCMessage.r, raw)
|
||||
|
|
|
@ -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(' ', '_')
|
||||
|
||||
|
||||
|
|
10
users.py
10
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"),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue