I've been doing this all wrong for a long time

This commit is contained in:
Luke Rogers 2014-02-14 19:43:36 +13:00
parent 27b62feb5f
commit b6558ccdd5
7 changed files with 43 additions and 31 deletions

View File

@ -25,10 +25,12 @@ db_ready = False
def db_init(db):
"""check to see that our db has the the encryption table."""
db.execute("create table if not exists encryption(encrypted, iv, "
"primary key(encrypted))")
db.commit()
db_ready = True
global db_ready
if not db_ready:
db.execute("create table if not exists encryption(encrypted, iv, "
"primary key(encrypted))")
db.commit()
db_ready = True
def get_salt(bot):
@ -42,8 +44,7 @@ def get_salt(bot):
@hook.command
def encrypt(inp, bot=None, db=None, notice=None):
"""encrypt <pass> <string> -- Encrypts <string> with <pass>. (<string> can only be decrypted using this bot)"""
if not db_ready:
db_init(db)
db_init(db)
split = inp.split(" ")

View File

@ -7,6 +7,8 @@ from util import hook, http, text, pyexec
re_lineends = re.compile(r'[\r\n]*')
db_ready = False
# some simple "shortcodes" for formatting purposes
shortcodes = {
'[b]': '\x02',
@ -18,9 +20,12 @@ shortcodes = {
def db_init(db):
db.execute("create table if not exists mem(word, data, nick,"
" primary key(word))")
db.commit()
global db_ready
if not db_ready:
db.execute("create table if not exists mem(word, data, nick,"
" primary key(word))")
db.commit()
db_ready = True
def get_memory(db, word):

View File

@ -7,17 +7,17 @@ db_ready = False
def db_init(db):
"""check to see that our db has the horoscope table and return a connection."""
db.execute("create table if not exists horoscope(nick primary key, sign)")
db.commit()
db_ready = True
global db_ready
if not db_ready:
db.execute("create table if not exists horoscope(nick primary key, sign)")
db.commit()
db_ready = True
@hook.command(autohelp=False)
def horoscope(inp, db=None, notice=None, nick=None):
"""horoscope <sign> -- Get your horoscope."""
if not db_ready:
db_init(db)
db_init(db)
# check if the user asked us not to save his details
dontsave = inp.endswith(" dontsave")

View File

@ -3,7 +3,7 @@ import re
from util import hook
db_inited = False
db_ready = False
def clean_sql(sql):
@ -11,8 +11,8 @@ def clean_sql(sql):
def db_init(db):
global db_inited
if db_inited:
global db_ready
if db_ready:
return
exists = db.execute("""
@ -32,7 +32,7 @@ def db_init(db):
db.commit()
db_inited = True
db_ready = True
def db_getall(db, nick, limit=-1):

View File

@ -6,15 +6,15 @@ from util import hook
# If False, all channels without a setting will have regex disabled
default_enabled = True
db_already_initiated = False
db_ready = False
def db_init(db):
global db_already_initiated
if not db_already_initiated:
db_already_initiated = True
global db_ready
if not db_ready:
db.execute("CREATE TABLE IF NOT EXISTS regexchans(channel PRIMARY KEY, status)")
db.commit()
db_ready = True
def get_status(db, channel):

View File

@ -11,10 +11,12 @@ db_ready = False
def db_init(db):
"""check to see that our db has the the seen table and return a connection."""
db.execute("create table if not exists seen_user(name, time, quote, chan, host, "
"primary key(name, chan))")
db.commit()
db_ready = True
global db_ready
if not db_ready:
db.execute("create table if not exists seen_user(name, time, quote, chan, host, "
"primary key(name, chan))")
db.commit()
db_ready = True
@hook.singlethread

View File

@ -6,13 +6,17 @@ import re
from util import hook, timesince
db_ready = False
def db_init(db):
"""check to see that our db has the tell table and return a dbection."""
db.execute("create table if not exists tell"
"(user_to, user_from, message, chan, time,"
"primary key(user_to, message))")
db.commit()
global db_ready
if not db_ready:
db.execute("create table if not exists tell"
"(user_to, user_from, message, chan, time,"
"primary key(user_to, message))")
db.commit()
db_ready = True
return db