diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8160c29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +cookies.py +sasl.py +users.py + +__pycache__/ diff --git a/bridge.py b/bridge.py index 9b6304b..499596d 100644 --- a/bridge.py +++ b/bridge.py @@ -8,6 +8,7 @@ from irc import IRC from shoutbox import Shoutbox from cookies import cookies from sasl import nick, password +from users import users LOG_FORMAT = "%(asctime)s [%(levelname)s] <%(filename)s> %(funcName)s: %(message)s" @@ -18,9 +19,11 @@ channels = ["hs", "projets", "annonces"] irc = IRC('irc.planet-casio.com', 6697) shoutbox = Shoutbox(cookies) + @irc.on(lambda m: m.to[1:] in channels) def handle_irc(m): - shoutbox.post(f"{m.author}: {m.text}", m.to[1:]) + shoutbox.post(m.author, m.text, m.to[1:], users) + @shoutbox.on(lambda m: m.channel in channels and m.author != "IRC") def handle_shoutbox(m): diff --git a/shoutbox.py b/shoutbox.py index cab7e23..5cf9a07 100644 --- a/shoutbox.py +++ b/shoutbox.py @@ -48,9 +48,18 @@ class Shoutbox(object): return callback - def post(self, msg, channel): - r.post("https://www.planet-casio.com/Fr/shoutbox/api/post", - data={"message": msg, "channel": channel}, cookies=self.cookies) + def post(self, user, msg, channel, users): + if any(user in t for t in users): + for i in users: + if i[1] == user: + r.post("https://www.planet-casio.com/Fr/shoutbox/api/post-as", + data={"user": i[0], "message": msg, "channel": channel}, + cookies=self.cookies) + else: + r.post("https://www.planet-casio.com/Fr/shoutbox/api/post-as", + data={"user": "IRC", "message": f"{user} : {msg}", "channel": channel}, + cookies=self.cookies) + class SBMessage(object): def __init__(self, raw, channel):