Initial commit: VPN Telegram bot (sanitized defaults)

This commit is contained in:
VPN Service
2026-07-26 23:21:41 +03:00
commit aaf04faa96
77 changed files with 33249 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
"""Алерты админам в 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)