override on_pubmsg, since we need to do things regardless of the normal command-addressed-to-bot flow

This commit is contained in:
Brian S. Stephan 2010-07-29 00:44:38 -05:00
parent bc4f2c6904
commit 87c4cec3f2
1 changed files with 31 additions and 2 deletions

View File

@ -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]