From 4b653eddcea551b7fae6579a2a36e54f651db5e2 Mon Sep 17 00:00:00 2001 From: Admin Date: Sun, 6 Sep 2026 19:48:49 +0400 Subject: [PATCH] refactor(architecture): decouple personal assistant from domovoy-bot, add alert_bridge to Maya --- docker-compose.yml | 10 +--------- handlers/__init__.py | 1 - main.py | 10 +++------- services/alert_bridge.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 services/alert_bridge.py diff --git a/docker-compose.yml b/docker-compose.yml index 6467649..767bd20 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,11 +8,11 @@ services: restart: always environment: - PYTHONPATH=/app:/app/services - - MUTT_DIR=/home/matrixhasyou/mutt - GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json - TZ=Europe/Ulyanovsk volumes: - /var/run/docker.sock:/var/run/docker.sock + - ./main.py:/app/main.py - ./logs:/app/logs - ./exports:/app/exports - ./data:/app/data @@ -20,10 +20,6 @@ services: - ./services:/app/services - ../libs/swarmlib:/app/swarmlib:ro - /home/matrixhasyou/domovoy_google_creds.json:/home/matrixhasyou/domovoy_google_creds.json:ro - - /home/matrixhasyou/mutt:/home/matrixhasyou/mutt:rw - - /home/matrixhasyou/domovoy_drive_sync.py:/home/matrixhasyou/domovoy_drive_sync.py:ro - - /home/matrixhasyou/.muttrc:/home/matrixhasyou/.muttrc:ro - - /mnt/nas/obsidian/data/vault:/vault:rw logging: driver: "json-file" options: @@ -38,7 +34,6 @@ services: restart: always environment: - PYTHONPATH=/app:/app/services - - MUTT_DIR=/home/matrixhasyou/mutt - GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json - TZ=Europe/Ulyanovsk volumes: @@ -50,9 +45,6 @@ services: - ./services:/app/services - ../libs/swarmlib:/app/swarmlib:ro - /home/matrixhasyou/domovoy_google_creds.json:/home/matrixhasyou/domovoy_google_creds.json:ro - - /home/matrixhasyou/mutt:/home/matrixhasyou/mutt:rw - - /home/matrixhasyou/domovoy_drive_sync.py:/home/matrixhasyou/domovoy_drive_sync.py:ro - - /home/matrixhasyou/.muttrc:/home/matrixhasyou/.muttrc:ro logging: driver: "json-file" options: diff --git a/handlers/__init__.py b/handlers/__init__.py index db6ad6a..756f075 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -23,5 +23,4 @@ from .achievements import router as achievements_router from .thanks import router as thanks_router from .events import router as events_router from .initiative_group import router as initiative_group_router -from .personal_inbox import router as personal_inbox_router diff --git a/main.py b/main.py index d82993e..39b4452 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,6 @@ from config import BOT_TOKEN, ADMIN_USER_ID from database.db import init_db # Импортируем роутеры -from handlers.voice import voice_router from handlers import ( admin_router, users_router, verification_router, chat_monitor_router, security_router, apartments_router, antimat_router, phones_router, @@ -33,6 +32,7 @@ from handlers import ( ) from handlers.mutual_aid import router as mutual_aid_router from services.scheduler import Scheduler +from services.alert_bridge import send_domovoy_alert # Настройка логирования logging.basicConfig( @@ -51,6 +51,7 @@ async def on_startup(bot: Bot): scheduler.start() try: await bot.send_message(ADMIN_USER_ID, '✅ LKM37 CORE v4.3 АКТИВИРОВАН') + await send_domovoy_alert("Сервис запущен", "Домовой МКД успешно запущен в автономном коммунальном режиме.") except: pass async def main(): @@ -58,10 +59,7 @@ async def main(): bot = get_bot() dp = Dispatcher(storage=MemoryStorage()) - # КРИТИЧЕСКИ ВАЖНО: voice_router должен быть САМЫМ ПЕРВЫМ - dp.include_router(voice_router) - - # Регистрация остальных + # Регистрация роутеров МКД dp.include_router(admin_router) dp.include_router(users_router) @@ -79,10 +77,8 @@ async def main(): from handlers.smart_broadcast import router as smart_broadcast_router from handlers.digest import router as digest_router - from handlers.personal_inbox import router as personal_inbox_router dp.include_router(smart_broadcast_router) dp.include_router(digest_router) - dp.include_router(personal_inbox_router) dp.startup.register(on_startup) diff --git a/services/alert_bridge.py b/services/alert_bridge.py new file mode 100644 index 0000000..d074476 --- /dev/null +++ b/services/alert_bridge.py @@ -0,0 +1,31 @@ +import logging +import aiohttp +import asyncio + +logger = logging.getLogger(__name__) + +# Токен личного бота Майи (@ktybdsqbot) и ID Александра +MAYA_BOT_TOKEN = "8065539545:AAECBnyjinUVVGv3vhtoWZ99tUmnT9sze-k" +ALEXANDER_CHAT_ID = 197957361 + +async def send_domovoy_alert(title: str, message: str, level: str = "INFO"): + """Отправляет служебный алерт от Домового напрямую в личный чат Майи Александру.""" + emoji = "🔔" if level == "INFO" else "⚠️" if level == "WARNING" else "🚨" + formatted_text = f"{emoji} [Домовой МКД] {title}\n\n{message}" + + url = f"https://api.telegram.org/bot{MAYA_BOT_TOKEN}/sendMessage" + payload = { + "chat_id": ALEXANDER_CHAT_ID, + "text": formatted_text, + "parse_mode": "HTML" + } + + try: + async with aiohttp.ClientSession() as session: + async with session.post(url, json=payload, timeout=10) as resp: + if resp.status == 200: + logger.info(f"✅ Alert forwarded to Maya bot: {title}") + else: + logger.warning(f"Failed to forward alert: {resp.status}") + except Exception as e: + logger.error(f"Error sending alert to Maya: {e}")