Create base_sqlite.py
Browse files- Akeno/utils/base_sqlite.py +41 -0
Akeno/utils/base_sqlite.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sqlite3
|
2 |
+
|
3 |
+
conn = sqlite3.connect('bot_prefix.db')
|
4 |
+
cursor = conn.cursor()
|
5 |
+
|
6 |
+
cursor.execute('''
|
7 |
+
CREATE TABLE IF NOT EXISTS prefixes (
|
8 |
+
user_id INTEGER PRIMARY KEY,
|
9 |
+
prefix TEXT NOT NULL
|
10 |
+
)
|
11 |
+
''')
|
12 |
+
|
13 |
+
conn.commit()
|
14 |
+
conn.close()
|
15 |
+
|
16 |
+
def set_prefix(user_id: int, prefix: str):
|
17 |
+
conn = sqlite3.connect('bot_prefix.db')
|
18 |
+
cursor = conn.cursor()
|
19 |
+
|
20 |
+
cursor.execute('''
|
21 |
+
INSERT INTO prefixes (user_id, prefix)
|
22 |
+
VALUES (?, ?)
|
23 |
+
ON CONFLICT(user_id) DO UPDATE SET prefix=excluded.prefix
|
24 |
+
''', (user_id, prefix))
|
25 |
+
|
26 |
+
conn.commit()
|
27 |
+
conn.close()
|
28 |
+
|
29 |
+
def get_prefix(user_id: int):
|
30 |
+
conn = sqlite3.connect('bot_prefix.db')
|
31 |
+
cursor = conn.cursor()
|
32 |
+
|
33 |
+
cursor.execute('SELECT prefix FROM prefixes WHERE user_id=?', (user_id,))
|
34 |
+
result = cursor.fetchone()
|
35 |
+
|
36 |
+
conn.close()
|
37 |
+
|
38 |
+
if result:
|
39 |
+
return result[0]
|
40 |
+
else:
|
41 |
+
return None
|