Бот для капчи в чатах
cfg.py
@@ -1,5 +1,6 @@
import logging
import os
import pathlib
from typing import Optional, Set
from aiogram import Bot, Dispatcher
@@ -10,6 +11,38 @@
load_dotenv()
def resolve_version() -> str:
    # Версия = короткий хэш коммита. Приоритет: env BOT_VERSION, затем .git,
    # затем fallback. Читаем .git напрямую, т.к. git в образе не установлен.
    env = os.getenv("BOT_VERSION")
    if env:
        return env
    git = pathlib.Path(__file__).resolve().parent / ".git"
    try:
        head = (git / "HEAD").read_text().strip()
        commit = head
        if head.startswith("ref:"):
            ref = head.split(" ", 1)[1].strip()
            loose = git / ref
            if loose.exists():
                commit = loose.read_text().strip()
            else:
                commit = ""
                packed = git / "packed-refs"
                if packed.exists():
                    for line in packed.read_text().splitlines():
                        parts = line.split()
                        if len(parts) == 2 and parts[1] == ref:
                            commit = parts[0]
                            break
        return commit[:7] if commit else "unknown"
    except Exception:
        return "unknown"
VERSION: str = resolve_version()
TOKEN: Optional[str] = os.getenv("BOT_TOKEN")
# Владелец бота: полный доступ везде, ограничить его нельзя.
OWNER_ID: int = int(os.getenv("OWNER_ID") or 0)