#!/usr/bin/env python import logging import sys 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] %(threadName)s <%(filename)s> %(funcName)s: %(message)s" logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG) channels = ["hs", "projets", "annonces"] irc = IRC('irc.planet-casio.com', 6697) shoutbox = Shoutbox(cookies) @irc.on(lambda m: m.to[1:] in channels and not m.author.endswith("[s]")) def handle_irc(m): if (m.text.startswith("\x01ACTION ")): m.text = m.text.replace("ACTION ", "[i]") shoutbox.post(m.author, m.text, m.to[1:], USERS) @shoutbox.on(lambda m: m.channel in channels) def handle_shoutbox(m): author = Shoutbox.normalize(m.author) shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}") irc.start(f"Shoutbox[{nick}]", password, nick) for c in channels: irc.join(f"#{c}") try: shoutbox.run() irc.run() except KeyboardInterrupt: irc.stop() shoutbox.stop() sys.exit(0)