53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class BotSettings:
|
|
bot_token: str
|
|
channel_id: int
|
|
channel_message_id: int
|
|
config_path: Path
|
|
state_path: Path
|
|
admin_ids: set[int]
|
|
|
|
|
|
def _parse_admin_ids(value: str) -> set[int]:
|
|
ids = set()
|
|
for chunk in value.split(","):
|
|
chunk = chunk.strip()
|
|
if chunk:
|
|
ids.add(int(chunk))
|
|
return ids
|
|
|
|
|
|
def load_settings() -> BotSettings:
|
|
load_dotenv()
|
|
|
|
bot_token = os.environ["BOT_TOKEN"]
|
|
channel_id = int(os.environ["CHANNEL_ID"])
|
|
channel_message_id = int(os.environ["CHANNEL_MESSAGE_ID"])
|
|
config_path = Path(os.environ.get("CONFIG_PATH", "config/actors.json"))
|
|
state_path = Path(os.environ.get("STATE_PATH", "data/state.json"))
|
|
admin_ids = _parse_admin_ids(os.environ.get("ADMIN_IDS", ""))
|
|
|
|
return BotSettings(
|
|
bot_token=bot_token,
|
|
channel_id=channel_id,
|
|
channel_message_id=channel_message_id,
|
|
config_path=config_path,
|
|
state_path=state_path,
|
|
admin_ids=admin_ids,
|
|
)
|
|
|
|
|
|
def load_actor_config(path: Path) -> dict:
|
|
with path.open("r", encoding="utf-8") as file:
|
|
return json.load(file)
|