bot: don't strip []s if no replacement happened

This commit is contained in:
Brian S. Stephan 2017-02-26 10:42:32 -06:00
parent c4714d3691
commit 6f9bbd304f
1 changed files with 14 additions and 9 deletions

View File

@ -244,15 +244,15 @@ class DrReactor(irc.client.Reactor):
# modules can do something with it. this calls the same
# event handlers in the same way as if this were a native
# event.
self.try_to_replace_event_text_with_module_text(connection, newevent)
# we have done all we can do with the sub-event. whatever
# the text of that event now is, we should replace the parent
# event's [] section with it.
oldtext = event.arguments[0]
newtext = oldtext.replace('['+subcmd+']', newevent.arguments[0])
log.debug("oldtext: '%s' newtext: '%s'", oldtext, newtext)
event.arguments[0] = newtext
replacements = self.try_to_replace_event_text_with_module_text(connection, newevent)
if replacements:
# we have done all we can do with the sub-event. whatever
# the text of that event now is, we should replace the parent
# event's [] section with it.
oldtext = event.arguments[0]
newtext = oldtext.replace('['+subcmd+']', newevent.arguments[0])
log.debug("oldtext: '%s' newtext: '%s'", oldtext, newtext)
event.arguments[0] = newtext
# we have now resolved the []. recursion will unfold, replacing
# it further and further, until we eventually get back to the
@ -275,6 +275,7 @@ class DrReactor(irc.client.Reactor):
"""
replacement = False
replies = []
# only do aliasing for pubmsg/privmsg
@ -306,6 +307,7 @@ class DrReactor(irc.client.Reactor):
log.debug("result: %s", result)
if result:
log.debug("appending %s to replies", result)
replacement = True
replies.append(result)
matching_handlers = sorted(
@ -318,11 +320,14 @@ class DrReactor(irc.client.Reactor):
log.debug("result: %s", result)
if result:
log.debug("appending %s to replies", result)
replacement = True
replies.append(result)
if len(replies):
event.arguments[0] = '\n'.join(replies)
return replacement
class IRCBot(irc.client.SimpleIRCClient):
"""A single-server IRC bot class."""