should make seen/tell case insensitive
This commit is contained in:
parent
b6ca89e079
commit
ef19fa7571
|
@ -17,14 +17,17 @@ def adapt_datetime(ts):
|
||||||
sqlite3.register_adapter(datetime, adapt_datetime)
|
sqlite3.register_adapter(datetime, adapt_datetime)
|
||||||
|
|
||||||
|
|
||||||
@hook.command(hook=r'(.*)', prefix=False, ignorebots=False)
|
@hook.tee
|
||||||
def seeninput(bot, input):
|
def seeninput(bot, input):
|
||||||
|
if input.command != 'PRIVMSG':
|
||||||
|
return
|
||||||
|
|
||||||
dbpath = os.path.join(bot.persist_dir, dbname)
|
dbpath = os.path.join(bot.persist_dir, dbname)
|
||||||
|
|
||||||
conn = dbconnect(dbpath)
|
conn = dbconnect(dbpath)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("insert or replace into seen(name, date, quote, chan)"
|
cursor.execute("INSERT OR REPLACE INTO seen(name, date, quote, chan)"
|
||||||
"values(?,?,?,?)", (input.nick, datetime.now(),
|
"values(?,?,?,?)", (input.nick.lower(), datetime.now(),
|
||||||
input.msg, input.chan))
|
input.msg, input.chan))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
@ -37,16 +40,17 @@ def seen(bot, input):
|
||||||
if len(input.msg) < 6:
|
if len(input.msg) < 6:
|
||||||
return seen.__doc__
|
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?"
|
return "Have you looked in a mirror lately?"
|
||||||
|
|
||||||
dbpath = os.path.join(bot.persist_dir, dbname)
|
dbpath = os.path.join(bot.persist_dir, dbname)
|
||||||
conn = dbconnect(dbpath)
|
conn = dbconnect(dbpath)
|
||||||
cursor = conn.cursor()
|
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))
|
cursor.execute(command, (query, input.chan))
|
||||||
results = cursor.fetchone()
|
results = cursor.fetchone()
|
||||||
|
|
||||||
|
@ -63,14 +67,11 @@ def seen(bot, input):
|
||||||
def dbconnect(db):
|
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 the seen table and return a connection."
|
||||||
conn = sqlite3.connect(db)
|
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, "
|
||||||
"seen(name varchar(30) not null, date datetime not null, "
|
"quote varchar(250) not null, chan varchar(32) not null, "
|
||||||
"quote varchar(250) not null, chan varchar(32) not null, "
|
"primary key(name, chan));")
|
||||||
"primary key(name, chan));")
|
conn.commit()
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
|
@ -23,13 +23,13 @@ def tellinput(bot, input):
|
||||||
conn = dbconnect(dbpath)
|
conn = dbconnect(dbpath)
|
||||||
|
|
||||||
cursor = conn.cursor()
|
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()
|
results = cursor.execute(command, (input.nick, input.chan)).fetchone()
|
||||||
|
|
||||||
|
|
||||||
if results[0] > 0:
|
if results[0] > 0:
|
||||||
command = "select id, user_from, quote, date from tell " \
|
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]
|
tell = cursor.execute(command, (input.nick, input.chan)).fetchall()[0]
|
||||||
more = results[0] - 1
|
more = results[0] - 1
|
||||||
reltime = timesince.timesince(datetime.fromtimestamp(tell[3]))
|
reltime = timesince.timesince(datetime.fromtimestamp(tell[3]))
|
||||||
|
@ -54,8 +54,8 @@ def showtells(bot, input):
|
||||||
conn = dbconnect(dbpath)
|
conn = dbconnect(dbpath)
|
||||||
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
command = "select id, user_from, quote, date from tell " \
|
command = "SELECT id, user_from, quote, date FROM tell " \
|
||||||
"where name = ? and chan = ?"
|
"WHERE name LIKE ? and chan = ?"
|
||||||
tells = cursor.execute(command, (input.nick, input.chan)).fetchall()
|
tells = cursor.execute(command, (input.nick, input.chan)).fetchall()
|
||||||
|
|
||||||
if(len(tells) > 0):
|
if(len(tells) > 0):
|
||||||
|
@ -114,25 +114,18 @@ def tell(bot, input):
|
||||||
|
|
||||||
|
|
||||||
def dbconnect(db):
|
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)
|
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"
|
||||||
conn.execute("create table if not exists tell(id integer primary key "
|
"autoincrement, name text not null, user_from text not null,"
|
||||||
"autoincrement, name varchar(30) not null, user_from "
|
"quote text not null, chan text not null, "
|
||||||
"varchar(30) not null, quote varchar(250) not null, "
|
"date datetime not null);")
|
||||||
"chan varchar(32) 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=?",
|
conn.commit()
|
||||||
("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()
|
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
Loading…
Reference in New Issue