orochi-discord/orochi/config.py

46 lines
1.2 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
2021-11-08 13:01:43 +00:00
brother_channel: int = None
brother_channel_webhook: int = None
2021-10-26 21:08:55 +00:00
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)