Merge branch 'main' into better-bridge

This commit is contained in:
Eragon 2022-03-11 22:34:18 +01:00
commit 4e0ccd8080
Signed by: Eragon
GPG Key ID: 087126EBFC725006
3 changed files with 11 additions and 6 deletions

View File

@ -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}")

8
irc.py
View File

@ -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:

View File

@ -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']