make IRC bot thread-safe

This commit is contained in:
sheepish
2022-06-01 15:53:41 +00:00
parent 61b466f683
commit 27a1f862bb

View File

@@ -1,3 +1,4 @@
import threading
import irc.bot
import irc.client
from datetime import datetime, timedelta
@@ -8,6 +9,7 @@ class ServerConnection(irc.client.ServerConnection):
super(ServerConnection, self).__init__(reactor)
self.last_ping = None
self.last_pong = None
self._write_mutex = threading.Lock()
def ping(self, target, target2=""):
"""Send a PING command."""
@@ -20,6 +22,10 @@ class ServerConnection(irc.client.ServerConnection):
"""Send a KILL command."""
self.send_items('KILL', nick, comment and ':' + comment)
def send_raw(self, string):
with self._write_mutex:
super().send_raw(string)
class Reactor(irc.client.Reactor):
connection_class = ServerConnection