-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
69 lines (58 loc) · 2.49 KB
/
config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import sqlite3
from sqlite3 import Error
def read_json(file_path):
with open(file_path, "r", encoding="utf8") as f:
return json.load(f)
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
except Error as e:
print(e)
return conn
def create_table(conn, create_table_sql):
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
config = read_json("config.json")
db = create_connection(config["DATABASE"]["FILE"])
sql_create_options_table = """ CREATE TABLE IF NOT EXISTS options (
id integer PRIMARY KEY,
name text NOT NULL,
value text
); """
sql_create_emotes_table = """CREATE TABLE IF NOT EXISTS emotes (
id integer PRIMARY KEY,
discord_id integer NOT NULL,
name text NOT NULL,
count integer
);"""
sql_create_groups_table = """CREATE TABLE IF NOT EXISTS groups (
id integer PRIMARY KEY,
name text NOT NULL,
active integer DEFAULT 1
);"""
sql_create_group_members_table = """CREATE TABLE IF NOT EXISTS group_members (
id integer PRIMARY KEY,
group_id integer NOT NULL,
discord_id integer NOT NULL,
name text NOT NULL,
FOREIGN KEY (group_id) REFERENCES groups (id)
);"""
sql_create_channels_table = """CREATE TABLE IF NOT EXISTS channels (
id integer PRIMARY KEY,
server_id integer NOT NULL,
channel_id integer NOT NULL,
channel_name text,
category_id integer,
category_name text,
position integer
);"""
create_table(db, sql_create_options_table)
create_table(db, sql_create_emotes_table)
create_table(db, sql_create_groups_table)
create_table(db, sql_create_group_members_table)
create_table(db, sql_create_channels_table)