28 lines
522 B
Python
28 lines
522 B
Python
from dataclasses import dataclass
|
|
from yaml import load
|
|
|
|
try:
|
|
from yaml import CLoader as Loader
|
|
except ImportError:
|
|
from yaml import Loader
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
token: str
|
|
client_id: str
|
|
admins: list
|
|
logo: str
|
|
mongo: dict
|
|
|
|
@classmethod
|
|
def from_yaml(cls, y):
|
|
instance = cls(**y)
|
|
return instance
|
|
|
|
|
|
def get_config(path: str = "config.yaml") -> Config:
|
|
with open(path) as f:
|
|
raw = f.read()
|
|
y = load(raw, Loader=Loader)
|
|
return Config.from_yaml(y)
|