This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/seen.py

52 lines
1.7 KiB
Python
Raw Normal View History

2013-09-04 12:30:04 +02:00
"""seen.py: written by sklnd in about two beers July 2009"""
2011-11-20 10:23:31 +01:00
import time
import re
from util import hook, timesince
2014-02-14 04:36:57 +01:00
db_ready = False
2011-11-20 10:23:31 +01:00
def db_init(db):
2013-09-04 12:30:04 +02:00
"""check to see that our db has the the seen table and return a connection."""
global db_ready
if not db_ready:
db.execute("create table if not exists seen_user(name, time, quote, chan, host, "
"primary key(name, chan))")
db.commit()
db_ready = True
2011-11-20 10:23:31 +01:00
@hook.command
def seen(inp, nick='', chan='', db=None, input=None):
"""seen <nick> <channel> -- Tell when a nickname was last in active in one of this bot's channels."""
2013-11-12 07:06:06 +01:00
2011-11-20 10:23:31 +01:00
if input.conn.nick.lower() == inp.lower():
return "You need to get your eyes checked."
if inp.lower() == nick.lower():
return "Have you looked in a mirror lately?"
2013-08-04 22:27:00 +02:00
if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", inp.lower()):
2012-03-12 21:50:55 +01:00
return "I can't look up that name, its impossible to use!"
2011-11-20 10:23:31 +01:00
if not db_ready:
db_init(db)
2011-11-20 10:23:31 +01:00
last_seen = db.execute("select name, time, quote from seen_user where name"
2011-11-20 10:23:31 +01:00
" like ? and chan = ?", (inp, chan)).fetchone()
if last_seen:
reltime = timesince.timesince(last_seen[1])
if last_seen[0] != inp.lower(): # for glob matching
inp = last_seen[0]
2013-09-04 12:30:04 +02:00
if last_seen[2][0:1] == "\x01":
2013-07-08 12:15:00 +02:00
return '{} was last seen {} ago: * {} {}'.format(inp, reltime, inp,
last_seen[2][8:-1])
else:
return '{} was last seen {} ago saying: {}'.format(inp, reltime, last_seen[2])
2011-11-20 10:23:31 +01:00
else:
2013-07-08 12:15:00 +02:00
return "I've never seen {} talking in this channel.".format(inp)