"""Алерты админам в Telegram (health / ошибки оплат).""" from __future__ import annotations import logging import time from typing import TYPE_CHECKING if TYPE_CHECKING: from aiogram import Bot from config import Settings logger = logging.getLogger(__name__) _last_sent: dict[str, float] = {} async def alert_admins( bot: Bot | None, settings: Settings, text: str, *, key: str = "generic", cooldown_sec: float = 300.0, ) -> None: if bot is None or not settings.admin_ids: return now = time.monotonic() last = _last_sent.get(key, 0.0) if now - last < cooldown_sec: return _last_sent[key] = now for admin_id in settings.admin_ids: try: await bot.send_message(admin_id, text, parse_mode="HTML") except Exception: # noqa: BLE001 logger.warning("admin alert failed id=%s", admin_id)