From 9a4429d3d9f1cf89ca10519d4ab597c56d9a46de Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 25 Jul 2010 09:34:28 -0500 Subject: [PATCH] seen command and tracking of when people speak in pubmsg. stored in config so that it can be loaded between sessions --- dr.botzo.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dr.botzo.py b/dr.botzo.py index bef3fbe..a0ae270 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -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 #####