-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_lib.py
47 lines (36 loc) · 1.34 KB
/
config_lib.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
import configparser
class MySQLConfig(object):
host: str
user: str
password: str
database: str
def __init__(self, mysql_host: str, mysql_user: str, mysql_password: str, mysql_database: str):
self.host = mysql_host
self.user = mysql_user
self.password = mysql_password
self.database = mysql_database
class Config(object):
token: str
secret: str
address: str
game: str
mysql: MySQLConfig
support_guild: int
def __init__(self, address: str, game: str, token: str, secret: str, mysql_host: str, mysql_user: str,
mysql_password: str,
mysql_database: str, support_guild: int):
self.token = token
self.address = address
self.secret = secret
self.game = game
self.support_guild = support_guild
self.mysql = MySQLConfig(mysql_host, mysql_user, mysql_password, mysql_database)
def parse_config(file_name: str) -> Config:
config = configparser.ConfigParser()
config.read(file_name)
general = config['general']
discord = config['discord']
mysql = config['mysql']
print(file_name)
return Config(general['address'], discord['game'], discord['TOKEN'], discord['SECRET'], mysql['host'],
mysql['user'], mysql['password'], mysql['database'], int(discord['support_guild']))