-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.py
36 lines (30 loc) · 1.26 KB
/
Database.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
28
29
30
31
32
33
34
35
36
import sqlite3, logging
logger = logging.getLogger(__name__)
class Database:
def __init__(self, channel):
self.db_name = f"AIDungeon_{channel.replace('#', '').lower()}.db"
sql = """
CREATE TABLE IF NOT EXISTS WhisperIgnore (
username TEXT COLLATE NOCASE,
PRIMARY KEY (username)
);
"""
logger.debug("Creating WhisperIgnore Database...")
self.execute(sql)
logger.debug("Finished creating WhisperIgnore Database.")
def execute(self, sql, values=None, fetch=False):
with sqlite3.connect(self.db_name) as conn:
cur = conn.cursor()
if values is None:
cur.execute(sql)
else:
cur.execute(sql, values)
conn.commit()
if fetch:
return cur.fetchall()
def add_whisper_ignore(self, username):
self.execute("INSERT OR IGNORE INTO WhisperIgnore(username) SELECT ?", (username,))
def check_whisper_ignore(self, username):
return self.execute("SELECT username FROM WhisperIgnore WHERE username = ?;", (username,), fetch=True)
def remove_whisper_ignore(self, username):
self.execute("DELETE FROM WhisperIgnore WHERE username = ?", (username,))