diff --git a/modules/Seen.py b/modules/Seen.py index c78e1e4..a97cf31 100644 --- a/modules/Seen.py +++ b/modules/Seen.py @@ -36,14 +36,43 @@ class Seen(Module): server.add_global_handler('pubmsg', self.on_pubmsg) server.add_global_handler('privmsg', self.on_privmsg) - def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): + # Overriding the default because we need stuff to occur before the addressed + # and so on checks. + + def on_pubmsg(self, connection, event): + nick = irclib.nm_to_n(event.source()) + userhost = irclib.nm_to_uh(event.source()) + replypath = event.target() + what = event.arguments()[0] + + admin_unlocked = False + # whatever it is, store it if not self.config.has_section('seen'): self.config.add_section('seen') self.config.set('seen', nick, userhost + '|:|' + datetime.utcnow().isoformat() + '|:|' + what) - # also see if it's a query + try: + if userhost == self.config.get('admin', 'userhost'): + admin_unlocked = True + except NoOptionError: pass + + # only do commands if the bot has been addressed directly + addressed_pattern = '^' + connection.get_nickname() + '[:,]?\s+' + addressed_re = re.compile(addressed_pattern) + + if not addressed_re.match(what): + return + else: + what = addressed_re.sub('', what) + + if replypath is not None: + what = self.try_recursion(connection, event, nick, userhost, replypath, what, admin_unlocked) + + self.do(connection, event, nick, userhost, replypath, what, admin_unlocked) + + def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): whats = what.split(' ') if whats[0] == 'seen' and len(whats) >= 2: query = whats[1]