Browse Source

Add token table, get_tokens(), add_token()

v2
Ceda EI 3 years ago
parent
commit
9261247115
  1. 3
      bot.py
  2. 17
      questable.py

3
bot.py

@ -557,6 +557,9 @@ queries = [
("CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state "
"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:
cursor.execute(query)

17
questable.py

@ -1,3 +1,6 @@
import uuid
class base_quest():
TABLE = None
@ -153,3 +156,17 @@ class player():
q = side_quest(self.DB, *row)
quests.append(q)
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…
Cancel
Save