Skip to content

Commit

Permalink
Fixed seen channel argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Yepoleb committed Jun 11, 2014
1 parent ed019f6 commit 24f3eb6
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions plugins/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from util import hook, timesince
import time
import re
import string

db_ready = []

Expand Down Expand Up @@ -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 <nick> [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)

0 comments on commit 24f3eb6

Please sign in to comment.