telegram-antispam-bot/bot/config.py
Artemii Peretiachenko 89c472708b Initial release: Telegram anti-spam bot
Includes join verification button, discuss-comment cleanup for non-members, and SQLite persistence.

Made-with: Cursor
2026-04-10 16:28:22 +02:00

45 lines
1.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
import os
from dotenv import load_dotenv
@dataclass(frozen=True)
class Config:
bot_token: str
chat_id: int | None
db_path: str
verify_window_seconds: int
thanks_ttl_seconds: int
def _get_int(name: str, default: int) -> int:
raw = os.getenv(name)
if raw is None or raw.strip() == "":
return default
return int(raw)
def load_config() -> Config:
load_dotenv()
bot_token = (os.getenv("BOT_TOKEN") or "").strip()
if not bot_token:
raise RuntimeError("BOT_TOKEN is required (set it in .env)")
chat_id_raw = (os.getenv("CHAT_ID") or "").strip()
chat_id = int(chat_id_raw) if chat_id_raw else None
db_path = (os.getenv("DB_PATH") or "./bot.sqlite3").strip()
verify_window_seconds = _get_int("VERIFY_WINDOW_SECONDS", 60)
thanks_ttl_seconds = _get_int("THANKS_TTL_SECONDS", 60)
return Config(
bot_token=bot_token,
chat_id=chat_id,
db_path=db_path,
verify_window_seconds=verify_window_seconds,
thanks_ttl_seconds=thanks_ttl_seconds,
)