Add token table, get_tokens(), add_token()
This commit is contained in:
parent
6e55bae42c
commit
9261247115
3
bot.py
3
bot.py
|
@ -557,6 +557,9 @@ queries = [
|
||||||
|
|
||||||
("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), extra varchar(10));"),
|
"varchar(10), extra varchar(10));"),
|
||||||
|
|
||||||
|
("CREATE TABLE IF NOT EXISTS tokens(chat_id int, token varchar(36),"
|
||||||
|
"UNIQUE(chat_id, token));"),
|
||||||
]
|
]
|
||||||
for query in queries:
|
for query in queries:
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
17
questable.py
17
questable.py
|
@ -1,3 +1,6 @@
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
class base_quest():
|
class base_quest():
|
||||||
TABLE = None
|
TABLE = None
|
||||||
|
|
||||||
|
@ -153,3 +156,17 @@ class player():
|
||||||
q = side_quest(self.DB, *row)
|
q = side_quest(self.DB, *row)
|
||||||
quests.append(q)
|
quests.append(q)
|
||||||
return quests
|
return quests
|
||||||
|
|
||||||
|
def get_tokens(self):
|
||||||
|
cursor = self.DB.cursor()
|
||||||
|
query = ('SELECT token FROM tokens WHERE chat_id=?')
|
||||||
|
cursor.execute(query, (self.CHAT_ID,))
|
||||||
|
tokens = list(map(lambda x: x[0], cursor))
|
||||||
|
return tokens
|
||||||
|
|
||||||
|
def add_token(self):
|
||||||
|
cursor = self.DB.cursor()
|
||||||
|
token = str(uuid.uuid4())
|
||||||
|
query = ('INSERT INTO tokens(chat_id, token) values(?, ?)')
|
||||||
|
cursor.execute(query, (self.CHAT_ID, token))
|
||||||
|
return token
|
||||||
|
|
Loading…
Reference in New Issue