-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.py
53 lines (42 loc) · 957 Bytes
/
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
from environs import Env
from pydantic import BaseModel
class Bot(BaseModel):
"""
Bot configuration
"""
token: str
admins: list
debug: bool
class Database(BaseModel):
"""
Database configuration
"""
host: str
port: int
username: str = None
password: str = None
database: str
class Config(BaseModel):
"""
Configuration model
"""
bot: Bot
db: Database = None
def load_config(path: str = None):
env = Env()
env.read_env(path)
return Config(
bot=Bot(
token=env.str("BOT_TOKEN"),
admins=env.list("ADMINS"),
debug=env.bool("DEBUG", False),
),
db=Database(
host=env.str("DB_HOST"),
port=env.int("DB_PORT"),
username=env.str("DB_USERNAME"),
password=env.str("DB_PASSWORD"),
database=env.str("DB_DATABASE"),
),
)
config = load_config()