Change state table to include extra field
This commit is contained in:
parent
3ffabd4ded
commit
1127673d28
2
bot.py
2
bot.py
|
@ -48,7 +48,7 @@ queries = [
|
||||||
"int);"),
|
"int);"),
|
||||||
|
|
||||||
("CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state "
|
("CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state "
|
||||||
"varchar(10));"),
|
"varchar(10), extra varchar(10));"),
|
||||||
]
|
]
|
||||||
for query in queries:
|
for query in queries:
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
14
questable.py
14
questable.py
|
@ -88,8 +88,8 @@ class player():
|
||||||
cursor.execute('SELECT * FROM state WHERE chat_id = ?', (chat_id,))
|
cursor.execute('SELECT * FROM state WHERE chat_id = ?', (chat_id,))
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if not row:
|
if not row:
|
||||||
cursor.execute('INSERT INTO state(chat_id, state) VALUES(?,?)',
|
cursor.execute('INSERT INTO state(chat_id, state, extra) '
|
||||||
(chat_id, 'none'))
|
'VALUES(?,?)', (chat_id, 'none', 0))
|
||||||
db.commit()
|
db.commit()
|
||||||
cursor.execute('SELECT * FROM points WHERE chat_id = ?', (chat_id,))
|
cursor.execute('SELECT * FROM points WHERE chat_id = ?', (chat_id,))
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
|
@ -100,15 +100,15 @@ class player():
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
cursor = self.DB.cursor()
|
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,))
|
cursor.execute(query, (self.CHAT_ID,))
|
||||||
output = cursor.fetchone()
|
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()
|
cursor = self.DB.cursor()
|
||||||
query = 'UPDATE state SET state=? WHERE chat_id=?'
|
query = 'UPDATE state SET state=?, extra=? WHERE chat_id=?'
|
||||||
cursor.execute(query, (state, self.CHAT_ID))
|
cursor.execute(query, (state, extra, self.CHAT_ID))
|
||||||
self.DB.commit()
|
self.DB.commit()
|
||||||
|
|
||||||
def get_points(self):
|
def get_points(self):
|
||||||
|
|
Loading…
Reference in New Issue