From ef19fa75713828711c88f5236ae2d8a9860366d4 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Fri, 20 Nov 2009 17:57:00 -0700 Subject: [PATCH] should make seen/tell case insensitive --- plugins/seen.py | 31 ++++++++++++++++--------------- plugins/tell.py | 33 +++++++++++++-------------------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/plugins/seen.py b/plugins/seen.py index 1bbcc60..64308f5 100644 --- a/plugins/seen.py +++ b/plugins/seen.py @@ -17,14 +17,17 @@ def adapt_datetime(ts): sqlite3.register_adapter(datetime, adapt_datetime) -@hook.command(hook=r'(.*)', prefix=False, ignorebots=False) +@hook.tee def seeninput(bot, input): + if input.command != 'PRIVMSG': + return + dbpath = os.path.join(bot.persist_dir, dbname) conn = dbconnect(dbpath) cursor = conn.cursor() - cursor.execute("insert or replace into seen(name, date, quote, chan)" - "values(?,?,?,?)", (input.nick, datetime.now(), + cursor.execute("INSERT OR REPLACE INTO seen(name, date, quote, chan)" + "values(?,?,?,?)", (input.nick.lower(), datetime.now(), input.msg, input.chan)) conn.commit() conn.close() @@ -37,16 +40,17 @@ def seen(bot, input): if len(input.msg) < 6: return seen.__doc__ - query = input.msg[6:].strip() + query = input.inp.strip() - if query == input.nick: + if query.lower() == input.nick.lower(): return "Have you looked in a mirror lately?" dbpath = os.path.join(bot.persist_dir, dbname) conn = dbconnect(dbpath) cursor = conn.cursor() - command = "select date, quote from seen where name = ? and chan = ?" + command = "SELECT date, quote FROM seen WHERE name LIKE ? AND chan = ?" \ + "ORDER BY date DESC" cursor.execute(command, (query, input.chan)) results = cursor.fetchone() @@ -63,14 +67,11 @@ def seen(bot, input): def dbconnect(db): "check to see that our db has the the seen table and return a connection." conn = sqlite3.connect(db) - results = conn.execute("select count(*) from sqlite_master where name=?", - ("seen", )).fetchone() - - if(results[0] == 0): - conn.execute("create table if not exists " - "seen(name varchar(30) not null, date datetime not null, " - "quote varchar(250) not null, chan varchar(32) not null, " - "primary key(name, chan));") - conn.commit() + + conn.execute("CREATE TABLE IF NOT EXISTS " + "seen(name varchar(30) not null, date datetime not null, " + "quote varchar(250) not null, chan varchar(32) not null, " + "primary key(name, chan));") + conn.commit() return conn diff --git a/plugins/tell.py b/plugins/tell.py index ee5327f..2394e9a 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -23,13 +23,13 @@ def tellinput(bot, input): conn = dbconnect(dbpath) cursor = conn.cursor() - command = "select count(name) from tell where name = ? and chan = ?" + command = "select count(name) from tell where name LIKE ? and chan = ?" results = cursor.execute(command, (input.nick, input.chan)).fetchone() if results[0] > 0: command = "select id, user_from, quote, date from tell " \ - "where name = ? and chan = ? limit 1" + "where name LIKE ? and chan = ? limit 1" tell = cursor.execute(command, (input.nick, input.chan)).fetchall()[0] more = results[0] - 1 reltime = timesince.timesince(datetime.fromtimestamp(tell[3])) @@ -54,8 +54,8 @@ def showtells(bot, input): conn = dbconnect(dbpath) cursor = conn.cursor() - command = "select id, user_from, quote, date from tell " \ - "where name = ? and chan = ?" + command = "SELECT id, user_from, quote, date FROM tell " \ + "WHERE name LIKE ? and chan = ?" tells = cursor.execute(command, (input.nick, input.chan)).fetchall() if(len(tells) > 0): @@ -114,25 +114,18 @@ def tell(bot, input): def dbconnect(db): - "check to see that our db has the the seen table and return a connection." + "check to see that our db has the tell table and return a connection." conn = sqlite3.connect(db) - results = conn.execute("select count(*) from sqlite_master where name=?", - ("tell", )).fetchone() - if results[0] == 0: - conn.execute("create table if not exists tell(id integer primary key " - "autoincrement, name varchar(30) not null, user_from " - "varchar(30) not null, quote varchar(250) not null, " - "chan varchar(32) not null, date datetime not null);") + conn.execute("CREATE TABLE IF NOT EXISTS tell(id integer primary key" + "autoincrement, name text not null, user_from text not null," + "quote text not null, chan text not null, " + "date datetime not null);") - conn.commit() + conn.execute("CREATE TABLE IF NOT EXISTS " + "tell_probation(name text, chan text," + "primary key(name, chan));") - results = conn.execute("select count(*) from sqlite_master where name=?", - ("tell_probation", )).fetchone() - if results[0] == 0: - conn.execute("create table if not exists "+ \ - "tell_probation(name varchar(30), chan varchar(32)," - "primary key(name, chan));") - conn.commit() + conn.commit() return conn