Some fixes
This commit is contained in:
parent
a1c7a592d6
commit
e796c96a7e
22
irc.py
22
irc.py
|
@ -1,6 +1,6 @@
|
|||
# Manage the IRC layer of GLaDOS
|
||||
|
||||
import logging, re, socket, ssl
|
||||
import logging, re, socket, ssl, time
|
||||
from functools import wraps
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
|
@ -10,7 +10,7 @@ class IRC(object):
|
|||
""" Initialize an IRC wrapper """
|
||||
# Public attributes
|
||||
self.connected = False # Simple lock
|
||||
self.run = False
|
||||
self.running = False
|
||||
|
||||
# Private attributes
|
||||
self._socket = ssl.create_default_context().wrap_socket(
|
||||
|
@ -25,7 +25,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._run = True
|
||||
self.running = True
|
||||
self._handler.start()
|
||||
|
||||
self._send(f"USER {nick} * * :{nick}")
|
||||
|
@ -38,9 +38,9 @@ class IRC(object):
|
|||
|
||||
def stop(self):
|
||||
""" Stop the IRC layer """
|
||||
self._send("QUIT")
|
||||
self._send("QUIT :Bye bye")
|
||||
logging.debug("STOP: sent QUIT message")
|
||||
self._run = False
|
||||
self.running = False
|
||||
self._handler.join()
|
||||
logging.debug("STOP: thread has terminated")
|
||||
self._socket.close()
|
||||
|
@ -95,7 +95,7 @@ class IRC(object):
|
|||
|
||||
def _handle(self, store=True):
|
||||
""" Handle raw messages from irc and manage ping """
|
||||
while self._run:
|
||||
while self.running:
|
||||
# Get incoming messages
|
||||
data = self._socket.recv(4096).decode()
|
||||
|
||||
|
@ -112,11 +112,17 @@ class IRC(object):
|
|||
|
||||
def _send(self, raw):
|
||||
""" Wrap and encode raw message to send """
|
||||
self._socket.send(f"{raw}\r\n".encode())
|
||||
try:
|
||||
self._socket.send(f"{raw}\r\n".encode())
|
||||
except OSError as e:
|
||||
logging.warning(e)
|
||||
logging.debug(f"_send: {raw}")
|
||||
|
||||
def _recv(self):
|
||||
m = self._inbox.get()
|
||||
try:
|
||||
m = self._inbox.get()
|
||||
except OSError as e:
|
||||
logging.warning(e)
|
||||
logging.debug(f"_recv: {m}")
|
||||
return m
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ class Shoutbox(object):
|
|||
for event, callback in self._callbacks:
|
||||
# client is not known or is disconnected
|
||||
author = Shoutbox.normalize(message.author)
|
||||
if author not in self.irc_clients \
|
||||
or self.irc_clients[author][0].run == False:
|
||||
if author not in self.irc_clients.keys() \
|
||||
or self.irc_clients[author][0].running == False:
|
||||
self.irc_clients[author] = [
|
||||
IRC('irc.planet-casio.com', 6697),
|
||||
datetime.datetime.now()
|
||||
|
|
Loading…
Reference in New Issue