shoutbridge/bridge.py

48 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-12-16 12:38:03 +01:00
#!/usr/bin/env python
2022-03-11 19:18:26 +01:00
import logging
import sys
2022-03-11 19:18:26 +01:00
from irc import IRC
from shoutbox import Shoutbox
from cookies import cookies
from sasl import nick, password
from users import USERS
2022-03-11 19:18:26 +01:00
2022-04-12 23:34:32 +02:00
LOG_FORMAT = "%(asctime)s [%(levelname)s] %(threadName)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
@irc.on(lambda m: m.to[1:] in channels and not m.author.endswith("[s]"))
2022-03-11 19:18:26 +01:00
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)
2022-03-11 19:18:26 +01:00
@shoutbox.on(lambda m: m.channel in channels)
2022-03-11 19:18:26 +01:00
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-04-13 20:51:05 +02:00
irc.start(f"Shoutbox[{nick}]", password, nick)
2022-03-11 19:18:26 +01:00
for c in channels:
irc.join(f"#{c}")
try:
shoutbox.run()
irc.run()
except KeyboardInterrupt:
irc.stop()
shoutbox.stop()
sys.exit(0)