-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_base.py
27 lines (20 loc) · 1.01 KB
/
data_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sqlite3
class BotDataBase:
def __init__(self, db_file):
self.conn = sqlite3.connect(db_file)
self.cursor = self.conn.cursor()
def toggle_on(self, user_id):
result = self.cursor.execute('UPDATE `users` SET `is_playing` = ? WHERE `user_id` = ?', (1, user_id,))
return self.conn.commit()
def toggle_off(self, user_id):
result = self.cursor.execute('UPDATE `users` SET `is_playing` = ? WHERE `user_id` = ?', (0, user_id,))
return self.conn.commit()
def is_playing(self, user_id):
result = self.cursor.execute('SELECT `is_playing` FROM `users` WHERE `user_id` = ?', (user_id,))
return result.fetchone()[0]
def user_exists(self, user_id):
result = self.cursor.execute('SELECT `user_id` FROM `users` WHERE `user_id` = ?', (user_id,))
return bool(len(result.fetchall()))
def add_user(self, user_id):
result = self.cursor.execute('INSERT INTO `users` (`user_id`) VALUES(?)', (user_id,))
return self.conn.commit()