From 1127673d28a2287ee4aee8df32a9cc1414e51ef3 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 31 Oct 2018 18:16:26 +0530 Subject: [PATCH] Change state table to include extra field --- bot.py | 2 +- questable.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 2e3c4e5..13e408f 100644 --- a/bot.py +++ b/bot.py @@ -48,7 +48,7 @@ queries = [ "int);"), ("CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state " - "varchar(10));"), + "varchar(10), extra varchar(10));"), ] for query in queries: cursor.execute(query) diff --git a/questable.py b/questable.py index 0bf0671..8053ba2 100644 --- a/questable.py +++ b/questable.py @@ -88,8 +88,8 @@ class player(): cursor.execute('SELECT * FROM state WHERE chat_id = ?', (chat_id,)) row = cursor.fetchone() if not row: - cursor.execute('INSERT INTO state(chat_id, state) VALUES(?,?)', - (chat_id, 'none')) + cursor.execute('INSERT INTO state(chat_id, state, extra) ' + 'VALUES(?,?)', (chat_id, 'none', 0)) db.commit() cursor.execute('SELECT * FROM points WHERE chat_id = ?', (chat_id,)) row = cursor.fetchone() @@ -100,15 +100,15 @@ class player(): def get_state(self): cursor = self.DB.cursor() - query = 'SELECT state FROM state WHERE chat_id=?' + query = 'SELECT state, extra FROM state WHERE chat_id=?' cursor.execute(query, (self.CHAT_ID,)) output = cursor.fetchone() - return output[0] + return {"state": output[0], "extra": output[1]} - def set_state(self, state): + def set_state(self, state, extra=0): cursor = self.DB.cursor() - query = 'UPDATE state SET state=? WHERE chat_id=?' - cursor.execute(query, (state, self.CHAT_ID)) + query = 'UPDATE state SET state=?, extra=? WHERE chat_id=?' + cursor.execute(query, (state, extra, self.CHAT_ID)) self.DB.commit() def get_points(self):