h/plugins/seen.py

57 lines
1.5 KiB
Python
Raw Normal View History

" seen.py: written by sklnd in about two beers July 2009"
2009-07-08 17:28:15 +00:00
import time
from util import hook, timesince
2009-07-08 17:28:15 +00:00
2009-11-21 00:57:00 +00:00
@hook.tee
2009-07-08 17:28:15 +00:00
def seeninput(bot, input):
2009-11-21 00:57:00 +00:00
if input.command != 'PRIVMSG':
return
conn = db_connect(bot, input.server)
cursor = conn.cursor()
cursor.execute("insert or replace into seen(name, time, quote, chan)"
"values(?,?,?,?)", (input.nick.lower(), time.time(),
2009-07-08 17:28:15 +00:00
input.msg, input.chan))
conn.commit()
2009-07-08 17:28:15 +00:00
@hook.command
def seen(bot, input):
".seen <nick> -- Tell when a nickname was last in active in irc"
if not input.inp:
return seen.__doc__
query = input.inp
2009-11-21 00:57:00 +00:00
if query.lower() == input.nick.lower():
return "Have you looked in a mirror lately?"
conn = db_connect(bot, input.server)
cursor = conn.cursor()
command = "select time, quote FROM seen WHERE name LIKE ? AND chan = ?"
cursor.execute(command, (query, input.chan))
results = cursor.fetchone()
if results:
reltime = timesince.timesince(results[0])
return '%s was last seen %s ago saying: %s' % \
2009-07-08 17:28:15 +00:00
(query, reltime, results[1])
else:
2009-07-08 17:28:15 +00:00
return "I've never seen %s" % query
def db_connect(bot, server):
2009-07-08 17:28:15 +00:00
"check to see that our db has the the seen table and return a connection."
conn = bot.get_db_connection(server)
2009-11-21 00:57:00 +00:00
conn.execute("create table if not exists seen(name, time, quote, chan, "
"primary key(name, chan))")
2009-11-21 00:57:00 +00:00
conn.commit()
return conn