Add player class, status functions to it.
This commit is contained in:
parent
a3f50b5334
commit
84c3e94c0f
32
questable.py
32
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 = side_quest(self, db, chat_id, qid, name, imp, diff, state, date)
|
||||||
q.add_to_db()
|
q.add_to_db()
|
||||||
return q
|
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()
|
||||||
|
|
Loading…
Reference in New Issue