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)
|
log.debug("OUTGOING PRIVMSG: t[%s] m[%s]", target, text)
|
||||||
self.connection.send_raw("PRIVMSG {0:s} :{1:s}".format(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.
|
"""Reply over IRC to replypath or return a string with the reply.
|
||||||
|
|
||||||
The primary utility for this is to properly handle recursion. The
|
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.
|
method will certainly have recursion do odd things with your module.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
event incoming event
|
event incoming event
|
||||||
replystr the message to reply with
|
replystr the message to reply with
|
||||||
stop whether or not to let other handlers see this
|
stop whether or not to let other handlers see this
|
||||||
|
explicit_target if event is none, use this for the destination
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The replystr if the event is inside recursion, or, potentially,
|
The replystr if the event is inside recursion, or, potentially,
|
||||||
"NO MORE" to stop other event handlers from acting.
|
"NO MORE" to stop other event handlers from acting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.debug("in reply for e[%s] r[%s]", event, replystr)
|
if event:
|
||||||
replypath = ircbotlib.reply_destination_for_event(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)
|
log.debug("replypath: %s", replypath)
|
||||||
|
|
||||||
if replystr is not None:
|
if replystr is not None:
|
||||||
recursing = getattr(event, '_recursing', False)
|
|
||||||
log.debug("determined recursing to be %s", recursing)
|
|
||||||
if recursing:
|
if recursing:
|
||||||
return replystr
|
return replystr
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user