Seen: convert to new-style module
This commit is contained in:
parent
319fb5b7e9
commit
0c7e4023ac
@ -30,6 +30,26 @@ class Seen(Module):
|
||||
|
||||
"""Track when people say things in public channels, and report on it."""
|
||||
|
||||
def register_handlers(self):
|
||||
"""Hook handler functions into the IRC library."""
|
||||
|
||||
self.irc.add_global_handler('pubmsg', self.on_pub_or_privmsg)
|
||||
self.irc.add_global_handler('privmsg', self.on_pub_or_privmsg)
|
||||
|
||||
self.irc.add_global_regex_handler(['pubmsg', 'privmsg'],
|
||||
r'^!seen\s+(\S+)$',
|
||||
self.seen)
|
||||
|
||||
def unregister_handlers(self):
|
||||
"""Unhook handler functions into the IRC library."""
|
||||
|
||||
self.irc.remove_global_handler('pubmsg', self.on_pub_or_privmsg)
|
||||
self.irc.remove_global_handler('privmsg', self.on_pub_or_privmsg)
|
||||
|
||||
self.irc.remove_global_regex_handler(['pubmsg', 'privmsg'],
|
||||
r'^!seen\s+(\S+)$',
|
||||
self.seen)
|
||||
|
||||
def do(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||
"""Track pubmsg/privmsg events, and if asked, report on someone."""
|
||||
|
||||
@ -49,17 +69,19 @@ class Seen(Module):
|
||||
seen_nick.seen_time = timezone.now()
|
||||
seen_nick.save()
|
||||
|
||||
match = re.search('^!seen\s+(\S+)$', what)
|
||||
if match:
|
||||
nick = match.group(1)
|
||||
try:
|
||||
seen_nick = SeenNick.objects.get(nick=nick, channel=where)
|
||||
local_time = timezone.localtime(seen_nick.seen_time).strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||
return self.irc.reply(event,
|
||||
"last saw {0:s} in {1:s} at {2:s} saying '{3:s}'."
|
||||
"".format(seen_nick.nick, seen_nick.channel,
|
||||
local_time, seen_nick.what))
|
||||
except SeenNick.DoesNotExist:
|
||||
return self.irc.reply(event, "i have not seen {0:s} in {1:s}.".format(nick, where))
|
||||
def seen(self, nick, userhost, event, from_admin, groups):
|
||||
"""Report on when a nick was last seen in a channel."""
|
||||
|
||||
nick, = groups
|
||||
source = event.target()
|
||||
try:
|
||||
seen_nick = SeenNick.objects.get(nick=nick, channel=source)
|
||||
local_time = timezone.localtime(seen_nick.seen_time).strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||
return self.irc.reply(event,
|
||||
"last saw {0:s} in {1:s} at {2:s} saying '{3:s}'."
|
||||
"".format(seen_nick.nick, seen_nick.channel,
|
||||
local_time, seen_nick.what))
|
||||
except SeenNick.DoesNotExist:
|
||||
return self.irc.reply(event, "i have not seen {0:s} in {1:s}.".format(nick, source))
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
|
Loading…
Reference in New Issue
Block a user