2009-07-05 00:52:17 +00:00
|
|
|
" seen.py: written by sklnd in about two beers July 2009"
|
|
|
|
|
2009-07-08 17:28:15 +00:00
|
|
|
import time
|
2009-07-05 00:52:17 +00:00
|
|
|
|
2009-07-08 17:04:30 +00:00
|
|
|
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
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db = bot.get_db_connection(input.server)
|
|
|
|
db_init(db)
|
|
|
|
db.execute("insert or replace into seen(name, time, quote, chan)"
|
2010-03-01 02:32:41 +00:00
|
|
|
"values(?,?,?,?)", (input.nick.lower(), time.time(), input.msg,
|
2010-02-02 04:42:34 +00:00
|
|
|
input.chan))
|
|
|
|
db.commit()
|
2009-07-05 00:52:17 +00:00
|
|
|
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2009-07-05 00:52:17 +00:00
|
|
|
@hook.command
|
2010-02-02 04:42:34 +00:00
|
|
|
def seen(inp, nick='', chan='', db=None):
|
2009-11-19 03:20:59 +00:00
|
|
|
".seen <nick> -- Tell when a nickname was last in active in irc"
|
2009-07-05 00:52:17 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
if not inp:
|
2009-07-05 00:52:17 +00:00
|
|
|
return seen.__doc__
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
if inp.lower() == nick.lower():
|
2009-07-05 00:52:17 +00:00
|
|
|
return "Have you looked in a mirror lately?"
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db_init(db)
|
2009-07-05 00:52:17 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
last_seen = db.execute("select name, time, quote from seen where name"
|
|
|
|
" like ? and chan = ?", (inp, chan)).fetchone()
|
2009-07-05 00:52:17 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
if last_seen:
|
|
|
|
reltime = timesince.timesince(last_seen[1])
|
2010-03-01 02:32:41 +00:00
|
|
|
if last_seen[0] != inp.lower(): # for glob matching
|
2010-02-02 04:42:34 +00:00
|
|
|
inp = last_seen[0]
|
2009-07-10 07:18:02 +00:00
|
|
|
return '%s was last seen %s ago saying: %s' % \
|
2010-02-02 04:42:34 +00:00
|
|
|
(inp, reltime, last_seen[2])
|
2009-07-05 00:52:17 +00:00
|
|
|
else:
|
2010-02-02 04:42:34 +00:00
|
|
|
return "I've never seen %s" % inp
|
2009-07-05 00:52:17 +00:00
|
|
|
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
def db_init(db):
|
2009-07-08 17:28:15 +00:00
|
|
|
"check to see that our db has the the seen table and return a connection."
|
2010-02-02 04:42:34 +00:00
|
|
|
db.execute("create table if not exists seen(name, time, quote, chan, "
|
2010-02-01 07:40:54 +00:00
|
|
|
"primary key(name, chan))")
|
2010-02-02 04:42:34 +00:00
|
|
|
db.commit()
|