shoutbridge/bridge.py

37 lines
875 B
Python
Raw Normal View History

2022-03-11 19:18:26 +01:00
import logging
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"
2022-03-11 21:30:54 +01:00
logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG)
2022-03-11 19:18:26 +01:00
channels = ["hs", "projets", "annonces"]
irc = IRC('irc.planet-casio.com', 6697)
shoutbox = Shoutbox(cookies)
2022-03-11 22:34:18 +01:00
2022-03-11 19:18:26 +01:00
@irc.on(lambda m: m.to[1:] in channels)
def handle_irc(m):
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]"))
def handle_shoutbox(m):
2022-03-11 21:30:54 +01:00
author = Shoutbox.normalize(m.author)
shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}")
2022-03-11 19:18:26 +01:00
2022-03-11 22:34:18 +01:00
irc.start("Shoutbox[Bot]", password, nick)
2022-03-11 19:18:26 +01:00
for c in channels:
irc.join(f"#{c}")
shoutbox.run()
irc.run()