refactor(architecture): decouple personal assistant from domovoy-bot, add alert_bridge to Maya
This commit is contained in:
parent
5bfe439a0f
commit
4b653eddce
4 changed files with 35 additions and 17 deletions
|
|
@ -8,11 +8,11 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
- PYTHONPATH=/app:/app/services
|
- PYTHONPATH=/app:/app/services
|
||||||
- MUTT_DIR=/home/matrixhasyou/mutt
|
|
||||||
- GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json
|
- GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json
|
||||||
- TZ=Europe/Ulyanovsk
|
- TZ=Europe/Ulyanovsk
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./main.py:/app/main.py
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
- ./exports:/app/exports
|
- ./exports:/app/exports
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
|
|
@ -20,10 +20,6 @@ services:
|
||||||
- ./services:/app/services
|
- ./services:/app/services
|
||||||
- ../libs/swarmlib:/app/swarmlib:ro
|
- ../libs/swarmlib:/app/swarmlib:ro
|
||||||
- /home/matrixhasyou/domovoy_google_creds.json:/home/matrixhasyou/domovoy_google_creds.json: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:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
|
|
@ -38,7 +34,6 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
- PYTHONPATH=/app:/app/services
|
- PYTHONPATH=/app:/app/services
|
||||||
- MUTT_DIR=/home/matrixhasyou/mutt
|
|
||||||
- GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json
|
- GOOGLE_CREDS_FILE=/home/matrixhasyou/domovoy_google_creds.json
|
||||||
- TZ=Europe/Ulyanovsk
|
- TZ=Europe/Ulyanovsk
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -50,9 +45,6 @@ services:
|
||||||
- ./services:/app/services
|
- ./services:/app/services
|
||||||
- ../libs/swarmlib:/app/swarmlib:ro
|
- ../libs/swarmlib:/app/swarmlib:ro
|
||||||
- /home/matrixhasyou/domovoy_google_creds.json:/home/matrixhasyou/domovoy_google_creds.json: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:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,4 @@ from .achievements import router as achievements_router
|
||||||
from .thanks import router as thanks_router
|
from .thanks import router as thanks_router
|
||||||
from .events import router as events_router
|
from .events import router as events_router
|
||||||
from .initiative_group import router as initiative_group_router
|
from .initiative_group import router as initiative_group_router
|
||||||
from .personal_inbox import router as personal_inbox_router
|
|
||||||
|
|
||||||
|
|
|
||||||
10
main.py
10
main.py
|
|
@ -22,7 +22,6 @@ from config import BOT_TOKEN, ADMIN_USER_ID
|
||||||
from database.db import init_db
|
from database.db import init_db
|
||||||
|
|
||||||
# Импортируем роутеры
|
# Импортируем роутеры
|
||||||
from handlers.voice import voice_router
|
|
||||||
from handlers import (
|
from handlers import (
|
||||||
admin_router, users_router, verification_router, chat_monitor_router,
|
admin_router, users_router, verification_router, chat_monitor_router,
|
||||||
security_router, apartments_router, antimat_router, phones_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 handlers.mutual_aid import router as mutual_aid_router
|
||||||
from services.scheduler import Scheduler
|
from services.scheduler import Scheduler
|
||||||
|
from services.alert_bridge import send_domovoy_alert
|
||||||
|
|
||||||
# Настройка логирования
|
# Настройка логирования
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -51,6 +51,7 @@ async def on_startup(bot: Bot):
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
try:
|
try:
|
||||||
await bot.send_message(ADMIN_USER_ID, '✅ <b>LKM37 CORE v4.3 АКТИВИРОВАН</b>')
|
await bot.send_message(ADMIN_USER_ID, '✅ <b>LKM37 CORE v4.3 АКТИВИРОВАН</b>')
|
||||||
|
await send_domovoy_alert("Сервис запущен", "Домовой МКД успешно запущен в автономном коммунальном режиме.")
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
@ -58,10 +59,7 @@ async def main():
|
||||||
bot = get_bot()
|
bot = get_bot()
|
||||||
dp = Dispatcher(storage=MemoryStorage())
|
dp = Dispatcher(storage=MemoryStorage())
|
||||||
|
|
||||||
# КРИТИЧЕСКИ ВАЖНО: voice_router должен быть САМЫМ ПЕРВЫМ
|
# Регистрация роутеров МКД
|
||||||
dp.include_router(voice_router)
|
|
||||||
|
|
||||||
# Регистрация остальных
|
|
||||||
dp.include_router(admin_router)
|
dp.include_router(admin_router)
|
||||||
dp.include_router(users_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.smart_broadcast import router as smart_broadcast_router
|
||||||
from handlers.digest import router as digest_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(smart_broadcast_router)
|
||||||
dp.include_router(digest_router)
|
dp.include_router(digest_router)
|
||||||
dp.include_router(personal_inbox_router)
|
|
||||||
|
|
||||||
|
|
||||||
dp.startup.register(on_startup)
|
dp.startup.register(on_startup)
|
||||||
|
|
|
||||||
31
services/alert_bridge.py
Normal file
31
services/alert_bridge.py
Normal file
|
|
@ -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} <b>[Домовой МКД] {title}</b>\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}")
|
||||||
Loading…
Reference in a new issue