should make seen/tell case insensitive

This commit is contained in:
Ryan Hitchman 2009-11-20 17:57:00 -07:00
parent b6ca89e079
commit ef19fa7571
2 changed files with 29 additions and 35 deletions

View File

@ -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,11 +67,8 @@ 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 "
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));")

View File

@ -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()
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),"
conn.execute("CREATE TABLE IF NOT EXISTS "
"tell_probation(name text, chan text,"
"primary key(name, chan));")
conn.commit()
return conn