diff --git a/bridge.py b/bridge.py index 3b8e4d4..8d4b999 100644 --- a/bridge.py +++ b/bridge.py @@ -7,7 +7,6 @@ from cookies import cookies from sasl import nick, password from users import users -import time LOG_FORMAT = "%(asctime)s [%(levelname)s] <%(filename)s> %(funcName)s: %(message)s" logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG) @@ -17,6 +16,7 @@ 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(m.author, m.text, m.to[1:], users) @@ -28,7 +28,7 @@ def handle_shoutbox(m): shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}") -irc.start("Shoutbox[darks]", password, nick) +irc.start("Shoutbox[Bot]", password, nick) for c in channels: irc.join(f"#{c}") diff --git a/irc.py b/irc.py index 5e1935f..d91f383 100644 --- a/irc.py +++ b/irc.py @@ -1,10 +1,14 @@ # Manage the IRC layer of GLaDOS -import logging, re, socket, ssl, time +import logging +import re +import socket +import ssl from functools import wraps from queue import Queue from threading import Thread + class IRC(object): def __init__(self, host, port): """ Initialize an IRC wrapper """ @@ -90,9 +94,7 @@ class IRC(object): return callback - # Private methods - def _handle(self, store=True): """ Handle raw messages from irc and manage ping """ while self.running: diff --git a/shoutbox.py b/shoutbox.py index 5482be3..188fd29 100644 --- a/shoutbox.py +++ b/shoutbox.py @@ -15,7 +15,7 @@ class Shoutbox(object): self.channels = {'annonces': 0, 'projets': 0, 'hs': 0} self.cookies = cookies self._callbacks = [] - self.irc_clients = {} # pseudo: [IRC(), date] + self.irc_clients = {} # pseudo: [IRC(), date] for channel, last_id in self.channels.items(): messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=text").text)['messages'] @@ -73,6 +73,8 @@ class Shoutbox(object): return callback def post(self, user, msg, channel, users): + if msg.startswith("ACTION"): + msg = msg.replace("ACTION", "/me") if any(user in t for t in users): for i in users: if i[1] == user: @@ -87,6 +89,7 @@ class Shoutbox(object): def normalize(pseudo): return pseudo.replace(' ', '_') + class SBMessage(object): def __init__(self, raw, channel): self.author = raw['author']