diff --git a/ircbot/bot.py b/ircbot/bot.py index df7b617..3d52e07 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -840,7 +840,7 @@ class IRCBot(irc.client.SimpleIRCClient): log.debug("OUTGOING PRIVMSG: t[%s] m[%s]", target, text) self.connection.send_raw("PRIVMSG {0:s} :{1:s}".format(target, text)) - def reply(self, event, replystr, stop=False): + def reply(self, event, replystr, stop=False, explicit_target=None): """Reply over IRC to replypath or return a string with the reply. The primary utility for this is to properly handle recursion. The @@ -853,22 +853,32 @@ class IRCBot(irc.client.SimpleIRCClient): method will certainly have recursion do odd things with your module. Args: - event incoming event - replystr the message to reply with - stop whether or not to let other handlers see this + event incoming event + replystr the message to reply with + stop whether or not to let other handlers see this + explicit_target if event is none, use this for the destination Returns: The replystr if the event is inside recursion, or, potentially, "NO MORE" to stop other event handlers from acting. """ - log.debug("in reply for e[%s] r[%s]", event, replystr) - replypath = ircbotlib.reply_destination_for_event(event) + if event: + log.debug("in reply for e[%s] r[%s]", event, replystr) + replypath = ircbotlib.reply_destination_for_event(event) + recursing = getattr(event, '_recursing', False) + log.debug("determined recursing to be %s", recursing) + elif explicit_target: + log.debug("in reply for e[NO EVENT] r[%s]", replystr) + replypath = explicit_target + recursing = False + else: + log.warning("reply() called with no event and no explicit target, aborting") + return + log.debug("replypath: %s", replypath) if replystr is not None: - recursing = getattr(event, '_recursing', False) - log.debug("determined recursing to be %s", recursing) if recursing: return replystr else: