50 lines
1.3 KiB
Python
50 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]
|
|
hidden_link_url: str
|
|
hidden_link_char: str
|
|
|
|
|
|
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()
|
|
|
|
return BotSettings(
|
|
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", "")),
|
|
hidden_link_url=os.environ.get("HIDDEN_LINK_URL", ""),
|
|
hidden_link_char=os.environ.get("HIDDEN_LINK_CHAR", "​"),
|
|
)
|
|
|
|
|
|
def load_actor_config(path: Path) -> dict:
|
|
with path.open("r", encoding="utf-8") as file:
|
|
return json.load(file)
|