From 84c3e94c0fc4557de367f0e31d8972ec984af10c Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 28 Oct 2018 16:04:52 +0530 Subject: [PATCH] Add player class, status functions to it. --- questable.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/questable.py b/questable.py index 7290eb7..9600aba 100644 --- a/questable.py +++ b/questable.py @@ -78,3 +78,35 @@ def add_side_quest(self, db, chat_id, qid, name=None, imp=None, diff=None, q = side_quest(self, db, chat_id, qid, name, imp, diff, state, date) q.add_to_db() return q + + +class player(): + def __init__(self, db, chat_id): + self.DB = db + self.CHAT_ID = chat_id + cursor = self.DB.cursor() + cursor.execute('SELECT * FROM state WHERE chat_id = ?') + row = cursor.fetchone() + if not row: + cursor.execute('INSERT INTO state(chat_id, state) VALUES(?,?)' + (chat_id, 'none')) + db.commit() + cursor.execute('SELECT * FROM points WHERE chat_id = ?') + row = cursor.fetchone() + if not row: + cursor.execute('INSERT INTO points(chat_id, points) VALUES(?,?)' + (chat_id, 0)) + db.commit() + + def get_state(self): + cursor = self.DB.cursor() + query = 'SELECT state FROM state WHERE chat_id=?' + cursor.execute(query, self.CHAT_ID) + output = cursor.fetchone() + return output[0] + + def set_state(self, state): + cursor = self.DB.cursor() + query = 'UPDATE state SET state=? WHERE chat_id=?' + cursor.execute(query, (state, self.CHAT_ID)) + self.DB.commit()