Add moar logging
This commit is contained in:
parent
9fb5f92e72
commit
8fb3434242
|
@ -29,7 +29,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(f"Shoutbox[{nick}]", password, nick)
|
||||
for c in channels:
|
||||
irc.join(f"#{c}")
|
||||
|
||||
|
|
10
irc.py
10
irc.py
|
@ -29,6 +29,7 @@ class IRC(object):
|
|||
def start(self, nick, password, sasl_nick=None):
|
||||
""" Start the IRC layer. Manage authentication as well """
|
||||
sasl_nick = sasl_nick or nick
|
||||
self.nick = nick
|
||||
self.running = True
|
||||
logging.debug("Thread start")
|
||||
self._handler.start()
|
||||
|
@ -74,6 +75,7 @@ class IRC(object):
|
|||
msg = IRCMessage(message)
|
||||
if msg:
|
||||
return msg
|
||||
logging.debug(f"skipped message {msg}")
|
||||
|
||||
def join(self, channel):
|
||||
""" Join a channel """
|
||||
|
@ -111,6 +113,7 @@ class IRC(object):
|
|||
elif len(m):
|
||||
if store:
|
||||
self._inbox.put(m)
|
||||
loggin.debug(f"_handle has quit: running={self.running}")
|
||||
|
||||
def _send(self, raw):
|
||||
""" Wrap and encode raw message to send """
|
||||
|
@ -118,14 +121,17 @@ class IRC(object):
|
|||
self._socket.send(f"{raw}\r\n".encode())
|
||||
except OSError as e:
|
||||
logging.warning(e)
|
||||
logging.debug(f"_send: {raw}")
|
||||
# Do not display password in logs
|
||||
if raw.startswith("AUTH"):
|
||||
raw = raw.split(":")[0] + ":*REDACTED*"
|
||||
logging.debug(raw)
|
||||
|
||||
def _recv(self):
|
||||
try:
|
||||
m = self._inbox.get()
|
||||
except OSError as e:
|
||||
logging.warning(e)
|
||||
logging.debug(f"_recv: {m}")
|
||||
logging.debug(m)
|
||||
return m
|
||||
|
||||
def _waitfor(self, condition):
|
||||
|
|
|
@ -78,13 +78,20 @@ class Shoutbox(object):
|
|||
while self.running:
|
||||
try:
|
||||
for channel, last_id in self.channels.items():
|
||||
# Do not spam with logs
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=text").text)['messages']
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
for m in messages:
|
||||
logging.debug(m)
|
||||
# Get channel id, parse SBMessage
|
||||
self.channels[channel] = m['id']
|
||||
message = SBMessage(m, channel)
|
||||
# If handler needs to be killed
|
||||
if not self.running:
|
||||
logging.debug("going to stop")
|
||||
break
|
||||
# For each callback defined with @decorator
|
||||
for event, callback in self._callbacks:
|
||||
author = Shoutbox.normalize(message.author)
|
||||
# client is not known or is disconnected
|
||||
|
@ -94,6 +101,7 @@ class Shoutbox(object):
|
|||
IRC('irc.planet-casio.com', 6697),
|
||||
datetime.datetime.now()
|
||||
]
|
||||
# Start a thread for new client
|
||||
self.irc_clients[author][0].start(f"{author}[s]", password, nick)
|
||||
logging.debug(f"{author} has joined IRC")
|
||||
# client is known but AFK
|
||||
|
@ -107,6 +115,7 @@ class Shoutbox(object):
|
|||
# kill afk clients
|
||||
for c in self.irc_clients.values():
|
||||
if datetime.datetime.now() - c[1] > datetime.timedelta(hours=1):
|
||||
logging.info(f"killing {c[0].nick}")
|
||||
c[0].stop()
|
||||
except Exception as e:
|
||||
logging.error(f"Faillure in Shoutbox thread {e}")
|
||||
|
|
Loading…
Reference in New Issue