From be4763f6a5b67d8f278c58c870a00af0ae55dc92 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 27 Apr 2011 22:11:37 -0500 Subject: [PATCH] DrBotIRC: fix an !alias add thinko with event handling ordering before, !alias commands were handled via an on_pubmsg() in DrBotIRC, which meant they happened (due to refactoring) after alias and recursion scanning happened in a more low-level routine. thus, if you were trying to add an alias that had recursion in it, your alias would be the outcome of that recursion, not the command to recurse. oops --- DrBotIRC.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/DrBotIRC.py b/DrBotIRC.py index d634ca4..8b6b05b 100644 --- a/DrBotIRC.py +++ b/DrBotIRC.py @@ -99,14 +99,12 @@ class DrBotIRC(irclib.IRC): self.server = DrBotServerConnection(self) self.connections.append(self.server) - self.server.add_global_handler('pubmsg', self.on_pubmsg, 1) - self.server.add_global_handler('privmsg', self.on_pubmsg, 1) - return self.server def _handle_event(self, connection, event): """Override event handler to do recursion.""" + self.try_alias_cmds(connection, event) self.try_recursion(connection, event) self.try_alias(connection, event) @@ -133,15 +131,24 @@ class DrBotIRC(irclib.IRC): if len(replies): event.arguments()[0] = '\n'.join(replies) - def on_pubmsg(self, connection, event): - """See if there is an alias ("!command") in the text, and if so, translate it into - an internal bot command and run it. + def try_alias_cmds(self, connection, event): + """See if there is an alias ("!command") in the text, and if so + do alias manipulation before any other recursion or aliasing. """ - nick = irclib.nm_to_n(event.source()) - userhost = irclib.nm_to_uh(event.source()) + try: + nick = irclib.nm_to_n(event.source()) + except (IndexError, AttributeError): + nick = '' + try: + userhost = irclib.nm_to_uh(event.source()) + except (IndexError, AttributeError): + userhost = '' replypath = event.target() - what = event.arguments()[0] + try: + what = event.arguments()[0] + except (IndexError, AttributeError): + what = '' admin_unlocked = False # privmsg