123
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 34s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 13s

This commit is contained in:
2026-04-02 18:04:04 +07:00
commit 02afbd23ec
31 changed files with 2624 additions and 0 deletions

52
session_bot/config.py Normal file
View File

@@ -0,0 +1,52 @@
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)