Pull out the config and history classes
This commit is contained in:
parent
d0865bd780
commit
c44f16dd8f
3 changed files with 96 additions and 55 deletions
33
config.py
33
config.py
|
@ -1,9 +1,34 @@
|
|||
"""Very simple config loading library"""
|
||||
import json
|
||||
from schema import Schema, And, Use
|
||||
import matching
|
||||
|
||||
CONFIG = "config.json"
|
||||
|
||||
|
||||
def load() -> dict:
|
||||
with open(CONFIG) as f:
|
||||
return json.load(f)
|
||||
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 load() -> Config:
|
||||
"""Load the config and validate it"""
|
||||
config = matching.load(CONFIG)
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue