orochi-discord/orochi/config.py

46 lines
1.2 KiB
Python

from dataclasses import asdict, dataclass, field
from pathlib import Path
import yaml
@dataclass
class Config:
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
brother_channel: int = None
brother_channel_webhook: int = None
player_roles: dict[str, int] = field(default_factory=dict)
@classmethod
def load(cls, filename=None) -> "Config":
if filename is None:
filename = Path(__file__).parent.parent / 'config.yml'
with open(filename) as config_file:
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)