Files
tg-admin-bot/main.py
2026-02-08 02:16:42 +03:00

60 lines
2.1 KiB
Python

import asyncio
import socket
from datetime import datetime
from app import bot, dp, cfg, ADMIN_ID
from keyboards import menu_kb
from services.docker import discover_containers, docker_watchdog
from services.alerts import monitor_resources, monitor_smart
from services.metrics import MetricsStore, start_sampler
from services.queue import worker as queue_worker
from services.notify import notify
from services.audit import AuditMiddleware, audit_start
from services.ssl_alerts import monitor_ssl
from services.external_checks import monitor_external
import state
import handlers.menu
import handlers.status
import handlers.docker
import handlers.backup
import handlers.artifacts
import handlers.system
import handlers.help
import handlers.callbacks
import handlers.arcane
import handlers.processes
async def notify_start():
await bot.send_message(
ADMIN_ID,
f"🤖 Bot started\n🖥 {socket.gethostname()}\n🕒 {datetime.now():%Y-%m-%d %H:%M}",
reply_markup=menu_kb,
)
async def main():
dp.message.middleware(AuditMiddleware(cfg))
dp.callback_query.middleware(AuditMiddleware(cfg))
audit_start(cfg)
state.DOCKER_MAP.clear()
state.DOCKER_MAP.update(await discover_containers(cfg))
if cfg.get("docker", {}).get("watchdog", True):
asyncio.create_task(docker_watchdog(state.DOCKER_MAP, notify, bot, ADMIN_ID))
if cfg.get("alerts", {}).get("enabled", True):
asyncio.create_task(monitor_resources(cfg, notify, bot, ADMIN_ID))
if cfg.get("alerts", {}).get("smart_enabled", True):
asyncio.create_task(monitor_smart(cfg, notify, bot, ADMIN_ID))
if cfg.get("npmplus", {}).get("alerts", {}).get("enabled", True):
asyncio.create_task(monitor_ssl(cfg, notify, bot, ADMIN_ID))
if cfg.get("external_checks", {}).get("enabled", True):
asyncio.create_task(monitor_external(cfg))
state.METRICS_STORE = MetricsStore()
asyncio.create_task(start_sampler(state.METRICS_STORE, interval=5))
asyncio.create_task(queue_worker())
await notify_start()
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())