matchy/config.py

39 lines
847 B
Python
Raw Normal View History

"""Very simple config loading library"""
from schema import Schema, And, Use
2024-08-10 10:58:31 +01:00
import files
FILE = "config.json"
class Config():
def __init__(self, data: dict):
self.__dict__ = data
@property
def token(self) -> str:
return self.__dict__["token"]
@property
def owners(self) -> list[int]:
return self.__dict__["owners"]
def reload(self) -> None:
"""Reload the config back into the dict"""
self.__dict__ = load().__dict__
def load() -> Config:
"""Load the config and validate it"""
2024-08-10 10:58:31 +01:00
config = files.load(FILE)
Schema(
{
# Discord bot token
"token": And(Use(str)),
# ids of owners authorised to use owner-only commands
"owners": And(Use(list[int])),
}
).validate(config)
return Config(config)