allow IRCBot.reply() to work eventless
reply() used to require an event, but all it used it for was to determine the destination and to identify recursion. basically, strictly only -replies-. we can make this a more robust privmsg, too, by adding explicit_target and inferring recursion as False. this will let basically any code currently using privmsg to use reply instead, and benefit from multi-line and line splitting bss/dr.botzo#21
This commit is contained in:
parent
010afd05ce
commit
23bb5cdd78
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user