3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

Irc: add locking for reply() calls (#437)

This commit is contained in:
James Lu 2017-03-24 00:57:21 -07:00
parent 0f472c8959
commit 99d3780773

View File

@ -62,6 +62,7 @@ class Irc(utils.DeprecatedAttributesObject):
self.connected = threading.Event() self.connected = threading.Event()
self.aborted = threading.Event() self.aborted = threading.Event()
self.reply_lock = threading.Lock()
self.pingTimer = None self.pingTimer = None
@ -558,22 +559,23 @@ class Irc(utils.DeprecatedAttributesObject):
loopback=True): loopback=True):
"""Replies to the last caller in the right context (channel or PM).""" """Replies to the last caller in the right context (channel or PM)."""
if private is None: with self.reply_lock:
# Allow using private replies as the default, if no explicit setting was given. if private is None:
private = conf.conf['bot'].get("prefer_private_replies") # Allow using private replies as the default, if no explicit setting was given.
private = conf.conf['bot'].get("prefer_private_replies")
# Private reply is enabled, or the caller was originally a PM # Private reply is enabled, or the caller was originally a PM
if private or (self.called_in in self.users): if private or (self.called_in in self.users):
if not force_privmsg_in_private: if not force_privmsg_in_private:
# For private replies, the default is to override the notice=True/False argument, # For private replies, the default is to override the notice=True/False argument,
# and send replies as notices regardless. This is standard behaviour for most # and send replies as notices regardless. This is standard behaviour for most
# IRC services, but can be disabled if force_privmsg_in_private is given. # IRC services, but can be disabled if force_privmsg_in_private is given.
notice = True notice = True
target = self.called_by target = self.called_by
else: else:
target = self.called_in target = self.called_in
self.msg(target, text, notice=notice, source=source, loopback=loopback) self.msg(target, text, notice=notice, source=source, loopback=loopback)
def error(self, text, **kwargs): def error(self, text, **kwargs):
"""Replies with an error to the last caller in the right context (channel or PM).""" """Replies with an error to the last caller in the right context (channel or PM)."""