Change state table to include extra field

This commit is contained in:
Ceda EI 2018-10-31 18:16:26 +05:30
parent 3ffabd4ded
commit 1127673d28
2 changed files with 8 additions and 8 deletions

2
bot.py
View File

@ -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)

View File

@ -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):