From 87b1d3d7f4a9d866d22a78e51e92c4022cda4fb1 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 21 Feb 2014 14:55:33 +1300 Subject: [PATCH] stuff --- plugins/correction.py | 3 ++- plugins/encrypt.py | 5 +++-- plugins/horoscope.py | 13 +++++++++---- plugins/lastfm.py | 8 ++++---- plugins/pre.py | 2 ++ plugins/tell.py | 3 +-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/plugins/correction.py b/plugins/correction.py index db370fa..112ecf8 100644 --- a/plugins/correction.py +++ b/plugins/correction.py @@ -9,7 +9,8 @@ def correction(inp, message=None, input=None, notice=None, db=None): else: nick = input.nick last_message = db.execute("select name, quote from seen_user where name" - " like ? and chan = ?", (nick.lower(), input.chan.lower())).fetchone() + " like :nick and chan = :chan", {'nick': nick.lower(), + 'chan': input.chan.lower()}).fetchone() if last_message: splitinput = input.msg.split("/") diff --git a/plugins/encrypt.py b/plugins/encrypt.py index 532b52b..119e37d 100644 --- a/plugins/encrypt.py +++ b/plugins/encrypt.py @@ -69,7 +69,8 @@ def encrypt(inp, bot=None, db=None, notice=None): # store the encoded text and IV in the DB for decoding later db.execute("insert or replace into encryption(encrypted, iv)" - "values(?,?)", (encoded, iv_encoded)) + "values(:encoded,:iv)", {'encoded': encoded, + 'iv': iv_encoded}) db.commit() return encoded @@ -97,7 +98,7 @@ def decrypt(inp, bot=None, db=None, notice=None): # get the encoded IV from the database and decode it iv_encoded = db.execute("select iv from encryption where" - " encrypted=?", (text,)).fetchone()[0] + " encrypted=:text", {'text': text}).fetchone()[0] iv = base64.b64decode(iv_encoded) # create AES cipher, decode text, decrypt text, and unpad it diff --git a/plugins/horoscope.py b/plugins/horoscope.py index 64d7960..49c91d1 100644 --- a/plugins/horoscope.py +++ b/plugins/horoscope.py @@ -14,6 +14,11 @@ def db_init(db): db_ready = True +@hook.onload +def init(paraml, db=None): + db_init(db) + + @hook.command(autohelp=False) def horoscope(inp, db=None, notice=None, nick=None): """horoscope -- Get your horoscope.""" @@ -29,8 +34,8 @@ def horoscope(inp, db=None, notice=None, nick=None): db.execute("create table if not exists horoscope(nick primary key, sign)") if not sign: - sign = db.execute("select sign from horoscope where nick=lower(:nick)", - {'nick':nick}).fetchone() + sign = db.execute("select sign from horoscope where " + "nick=lower(:nick)", {'nick': nick}).fetchone() if not sign: notice("horoscope -- Get your horoscope") return @@ -49,8 +54,8 @@ def horoscope(inp, db=None, notice=None, nick=None): return "Could not get the horoscope for {}.".format(inp) if inp and not dontsave: - db.execute("insert or replace into horoscope(nick, sign) values (:nick,:signS)", - {'nick':nick.lower(), 'sign': sign}) + db.execute("insert or replace into horoscope(nick, sign) values (:nick, :sign)", + {'nick': nick.lower(), 'sign': sign}) db.commit() return result diff --git a/plugins/lastfm.py b/plugins/lastfm.py index 87ca6e7..36e2889 100644 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -25,8 +25,8 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): db.execute("create table if not exists lastfm(nick primary key, acc)") if not user: - user = db.execute("select acc from lastfm where nick=lower(?)", - (nick,)).fetchone() + user = db.execute("select acc from lastfm where nick=lower(:nick)", + {'nick': nick}).fetchone() if not user: notice(lastfm.__doc__) return @@ -76,8 +76,8 @@ def lastfm(inp, nick='', db=None, bot=None, notice=None): out += ending if inp and not dontsave: - db.execute("insert or replace into lastfm(nick, acc) values (?,?)", - (nick.lower(), user)) + db.execute("insert or replace into lastfm(nick, acc) values " + "(:nick, :account)", {'nick': nick.lower(), 'account': user}) db.commit() return out diff --git a/plugins/pre.py b/plugins/pre.py index f4e61a3..4d0ffcc 100644 --- a/plugins/pre.py +++ b/plugins/pre.py @@ -36,3 +36,5 @@ def pre(inp): size = '' return '{} - {}{} - {} ({} ago)'.format(section, name, size, date_string, since) + +print pre("top gear") diff --git a/plugins/tell.py b/plugins/tell.py index 2afaac7..38e80ed 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -23,8 +23,7 @@ def db_init(db): def get_tells(db, user_to): return db.execute("select user_from, message, time, chan from tell where" - " user_to=lower(:user) order by time", - {'user': user_to}).fetchall() + " user_to=lower(:user) order by time", {'user': user_to}).fetchall() @hook.singlethread