diff --git a/plugins/history.py b/plugins/history.py index 9deda9cc..5e2c3667 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -2,6 +2,7 @@ from util import hook, timesince import time import re +import string db_ready = [] @@ -61,29 +62,36 @@ def resethistory(inp, input=None, conn=None): @hook.command def seen(inp, nick='', chan='', db=None, input=None, conn=None): """seen [channel] -- Tell when a nickname was last in active in one of this bot's channels.""" - - if input.conn.nick.lower() == inp.lower(): + + args = inp.split() + lookup_nick = args[0] + if len(args) > 1: + lookup_chan = args[1] + else: + lookup_chan = chan + + if input.conn.nick.lower() == lookup_nick.lower(): return "You need to get your eyes checked." - if inp.lower() == nick.lower(): + if lookup_nick.lower() == nick.lower(): return "Have you looked in a mirror lately?" - if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", inp.lower()): + if any(c not in (string.ascii_letters + string.digits + "_-\[]{}^`|") for c in lookup_nick): return "I can't look up that name, its impossible to use!" db_init(db, conn.name) - last_seen = db.execute("select name, time, quote from seen_user where name" - " like ? and chan = ?", (inp, chan)).fetchone() + last_seen = db.execute("SELECT name, time, quote FROM seen_user WHERE name" + " like ? and chan = ?", (lookup_nick, lookup_chan)).fetchone() if last_seen: reltime = timesince.timesince(last_seen[1]) - if last_seen[0] != inp.lower(): # for glob matching - inp = last_seen[0] + if last_seen[0] != lookup_nick.lower(): # for glob matching + lookup_nick = last_seen[0] if last_seen[2][0:1] == "\x01": - return '{} was last seen {} ago: * {} {}'.format(inp, reltime, inp, + return '{} was last seen {} ago: * {} {}'.format(lookup_nick, reltime, lookup_nick, last_seen[2][8:-1]) else: - return '{} was last seen {} ago saying: {}'.format(inp, reltime, last_seen[2]) + return '{} was last seen {} ago saying: {}'.format(lookup_nick, reltime, last_seen[2]) else: - return "I've never seen {} talking in this channel.".format(inp) + return "I've never seen {} talking in this channel.".format(lookup_nick)