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