seen command and tracking of when people speak in pubmsg. stored in config so that it can be loaded between sessions

This commit is contained in:
Brian S. Stephan 2010-07-25 09:34:28 -05:00
parent 327c519220
commit 9a4429d3d9
1 changed files with 34 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python2.6
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
from datetime import datetime
import os
import re
import sys
@ -71,6 +72,31 @@ def sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what,
connection.privmsg(replypath, 'removed ' + channel + ' from autojoin')
except NoOptionError: pass
#####
# sub_add_to_seen
# when someone says a pubmsg, keep it in the config
#####
def sub_add_to_seen(connection, event, nick, userhost, what):
if not config.has_section('seen'):
config.add_section('seen')
config.set('seen', nick, userhost + ',' + datetime.now().isoformat() + ',' + what)
#####
# sub_report_seen
# report when a person has been seen, based on config
#####
def sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked):
if what.split(' ')[0] == 'seen':
query = what.split(' ')[1]
try:
seendata = config.get('seen', query).split(',')
converted = datetime.strptime(seendata[1], "%Y-%m-%dT%H:%M:%S.%f")
connection.privmsg(replypath, 'last saw ' + query + ' at ' + converted.strftime("%Y/%m/%d %H:%M:%S") + ' saying \'' + seendata[2] + '\'')
except NoOptionError: pass
#####
# on_connect
# handler for when the bot has connected to IRC
@ -115,6 +141,9 @@ def on_privmsg(connection, event):
sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked)
# standard commands
sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked)
#####
# on_pubmsg
# public messages in a channel where the bot is
@ -133,6 +162,8 @@ def on_pubmsg(connection, event):
admin_unlocked = True
except NoOptionError: pass
sub_add_to_seen(connection, event, nick, userhost, what)
# only do commands if the bot has been addressed directly
addressed_pattern = '^' + botnick + '[:,]?\s+'
addressed_re = re.compile(addressed_pattern)
@ -150,6 +181,9 @@ def on_pubmsg(connection, event):
sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked)
# standard commands
sub_report_seen(connection, event, nick, userhost, replypath, what, admin_unlocked)
#####
# init
#####