seen: make handle_seeing a @staticmethod

This commit is contained in:
Brian S. Stephan 2015-05-19 21:55:11 -05:00
parent e77dc571be
commit 2fbd76dba6
1 changed files with 23 additions and 23 deletions

View File

@ -20,8 +20,8 @@ class Seen(Plugin):
def start(self):
"""Hook handler functions into the IRC library."""
self.connection.add_global_handler('pubmsg', handle_seeing)
self.connection.add_global_handler('privmsg', handle_seeing)
self.connection.add_global_handler('pubmsg', self.handle_seeing)
self.connection.add_global_handler('privmsg', self.handle_seeing)
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!seen\s+(\S+)$', self.handle_seen)
@ -30,13 +30,32 @@ class Seen(Plugin):
def stop(self):
"""Unhook handler functions into the IRC library."""
self.connection.remove_global_handler('pubmsg', handle_seeing)
self.connection.remove_global_handler('privmsg', handle_seeing)
self.connection.remove_global_handler('pubmsg', self.handle_seeing)
self.connection.remove_global_handler('privmsg', self.handle_seeing)
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_seen)
super(Seen, self).stop()
@staticmethod
def handle_seeing(connection, event):
"""Track pubmsg/privmsg events."""
userhost = event.source
nick = irc.client.NickMask(event.source).nick
where = event.target
what = event.arguments[0]
log.debug("userhost %s, nick %s, where %s, what '%s'", userhost, nick, where, what)
# store the event. only learn events with real wheres
if where:
seen_nick, c = SeenNick.objects.get_or_create(nick=nick, channel=where)
seen_nick.host = userhost
seen_nick.what = what
seen_nick.seen_time = timezone.now()
seen_nick.save()
def handle_seen(self, connection, event, match):
"""Report on when a nick was last seen in a channel."""
@ -55,23 +74,4 @@ class Seen(Plugin):
return self.bot.reply(event, "i have not seen {0:s} in {1:s}.".format(query_nick, source))
def handle_seeing(connection, event):
"""Track pubmsg/privmsg events."""
userhost = event.source
nick = irc.client.NickMask(event.source).nick
where = event.target
what = event.arguments[0]
log.debug("userhost %s, nick %s, where %s, what '%s'", userhost, nick, where, what)
# store the event. only learn events with real wheres
if where:
seen_nick, c = SeenNick.objects.get_or_create(nick=nick, channel=where)
seen_nick.host = userhost
seen_nick.what = what
seen_nick.seen_time = timezone.now()
seen_nick.save()
plugin = Seen