From 644b2ea6302f70b1e2e746f482901ce929c5dd0a Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 14 Apr 2016 16:44:27 +0100 Subject: [PATCH] added a new settings table for bot settings in general. --- Database.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Database.py b/Database.py index 3f102915..c453b396 100644 --- a/Database.py +++ b/Database.py @@ -11,6 +11,7 @@ class Database(object): self.cursors = {} self.make_servers_table() + self.make_bot_settings_table() self.make_server_settings_table() self.make_channel_settings_table() self.make_user_settings_table() @@ -30,6 +31,12 @@ class Database(object): username TEXT, realname TEXT)""") except sqlite3.Error as e: pass + def make_bot_settings_table(self): + try: + self.cursor().execute("""CREATE TABLE bot_settings + (setting TEXT PRIMARY KEY, value TEXT)""") + except sqlite3.Error as e: + pass def make_server_settings_table(self): try: self.cursor().execute("""CREATE TABLE server_settings @@ -58,6 +65,29 @@ class Database(object): except sqlite3.Error as e: pass + def set_bot_setting(self, setting, value): + self.cursor().execute("""INSERT OR REPLACE INTO bot_settings + VALUES (?, ?)""", [setting.lower(), json.dumps(value)]) + def get_bot_setting(self, setting, default=None): + self.cursor().execute("""SELECT value FROM bot_settings + WHERE setting=?""", [setting.lower()]) + value = self.cursor().fetchone() + if value: + return json.loads(value[0]) + return default + def find_bot_settings(self, pattern, default=[]): + self.cursor().execute("""SELECT setting, value FROM bot_settings + WHERE setting LIKE ?""", [pattern.lower()]) + values = self.cursor().fetchall() + if values: + for i, value in enumerate(values): + values[i] = value[0], json.loads(value[1]) + return values + return default + def del_bot_setting(self, setting): + self.cursor().execute("""DELETE FROM bot_settings WHERE + setting=?""", [setting.lower()]) + def set_server_setting(self, server_id, setting, value): self.cursor().execute("""INSERT OR REPLACE INTO server_settings VALUES (?, ?, ?)""", [server_id, setting.lower(),