orochi-discord/orochi/config.py

50 lines
1.3 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
sisters_channel: int = None
player_roles: dict[str, int] = field(default_factory=dict)
http_host: str = '127.0.0.1'
http_port: int = 5000
http_debug: bool = True
@classmethod
def load(cls, filename: str | None = 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: str | None = 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)