From 79ebfe229a95af4d329d5ef2d4af51c68fd85efa Mon Sep 17 00:00:00 2001 From: Sindastra Date: Mon, 18 Jan 2016 00:00:17 +0100 Subject: [PATCH] Fixed issue #218 Fixed regular expression Fixed typo Updated return messages to include the channel --- plugins/history.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/history.py b/plugins/history.py index 867b86af9..867c984a7 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -93,8 +93,15 @@ def seen(text, nick, chan, db, event): """ - if not re.match("^[A-Za-z0-9_|\^\*\`.\-\]\[\{\}\\\\]*$", text.lower()): - return "I can't look up that name, its impossible to use!" + nick_match = re.match("[A-Za-z0-9_|.\-\]\[]+", text.lower()) + if nick_match: + name = nick_match.group(0) + else: + return "I can't look up that name, it's impossible to use!" + + channel_match = re.search("#.+$", text.lower()) + if channel_match: + chan = channel_match.group(0) if '_' in text: text = text.replace("_", "/_") @@ -102,15 +109,16 @@ def seen(text, nick, chan, db, event): last_seen = db.execute("select name, time, quote from seen_user where name like :name escape '/' and chan = :chan", {'name': text, 'chan': chan}).fetchone() - text = text.replace("/", "") + last_seen = db.execute("select name, time, quote from seen_user where name like :name and chan = :chan", + {'name': name, 'chan': chan}).fetchone() if last_seen: reltime = timeformat.time_since(last_seen[1]) - if last_seen[0] != text.lower(): # for glob matching - text = last_seen[0] + if last_seen[0] != name.lower(): # for glob matching + name = last_seen[0] if last_seen[2][0:1] == "\x01": - return '{} was last seen {} ago: * {} {}'.format(text, reltime, text, last_seen[2][8:-1]) + return '{} was last seen in {} {} ago: * {} {}'.format(name, chan, reltime, name, last_seen[2][8:-1]) else: - return '{} was last seen {} ago saying: {}'.format(text, reltime, last_seen[2]) + return '{} was last seen in {} {} ago saying: {}'.format(name, chan, reltime, last_seen[2]) else: - return "I've never seen {} talking in this channel.".format(text) + return "I've never seen {} talking in {}.".format(name, chan)