diff --git a/bot.py b/bot.py index 2a0db09..ee3ebd0 100644 --- a/bot.py +++ b/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) diff --git a/questable.py b/questable.py index da5eb7a..40791b8 100644 --- a/questable.py +++ b/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