orochi-discord/orochi/config.py

45 lines
1.1 KiB
Python
Raw Normal View History

2021-10-26 21:08:55 +00:00
from dataclasses import asdict, dataclass, field
from pathlib import Path
2021-10-26 19:05:45 +00:00
import yaml
@dataclass
class Config:
2021-10-26 21:08:55 +00:00
PLAYERS = [
"Kamui",
"Oji",
"Dan",
"Tora",
"Delphine",
"Philia",
"Hanabi",
"Nona",
"Ennea",
]
discord_token: str = ""
guild: int = None
vote_category: int = None
secret_category: int = None
vote_channels: dict[str, int] = field(default_factory=dict)
backdoor_channel: int = None
telepathy_channel: int = None
left_channel: int = None
player_roles: dict[str, int] = field(default_factory=dict)
2021-10-26 19:05:45 +00:00
@classmethod
2021-10-26 21:08:55 +00:00
def load(cls, filename=None) -> "Config":
if filename is None:
filename = Path(__file__).parent.parent / 'config.yml'
2021-10-26 19:05:45 +00:00
with open(filename) as config_file:
2021-10-26 21:08:55 +00:00
return Config(**(yaml.safe_load(config_file) or {}))
def save(self, filename=None) -> None:
if filename is None:
filename = Path(__file__).parent.parent / 'config.yml'
with open(filename, 'w') as config_file:
yaml.safe_dump(asdict(self), config_file)