#!/usr/bin/env python3 import logging import asyncio import sys import os from pathlib import Path # Добавляем путь к проекту BASE_DIR = Path(__file__).resolve().parent sys.path.insert(0, str(BASE_DIR)) # Добавляем путь к библиотекам роя LIBS_DIR = BASE_DIR.parent.parent / "libs" if LIBS_DIR.exists(): sys.path.insert(0, str(LIBS_DIR)) from aiogram import Bot, Dispatcher from aiogram.enums import ParseMode from aiogram.fsm.storage.memory import MemoryStorage from config import BOT_TOKEN, ADMIN_USER_ID from database.db import init_db # Импортируем роутеры from handlers import ( admin_router, users_router, verification_router, chat_monitor_router, security_router, apartments_router, antimat_router, phones_router, polls_router, antispam_router, ratelimit_router, schedule_router, ads_router, payments_router, multicount_router, topics_router, toxicity_router, profile_history_router, achievements_router, thanks_router, events_router, initiative_group_router ) 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( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler('logs/bot.log', encoding='utf-8'), logging.StreamHandler() ] ) logger = logging.getLogger(__name__) async def on_startup(bot: Bot): await init_db() scheduler = Scheduler(bot) scheduler.start() try: await bot.send_message(ADMIN_USER_ID, '✅ LKM37 CORE v4.3 АКТИВИРОВАН') await send_domovoy_alert("Сервис запущен", "Домовой МКД успешно запущен в автономном коммунальном режиме.") except: pass async def main(): from bot_instance import get_bot bot = get_bot() dp = Dispatcher(storage=MemoryStorage()) # Регистрация роутеров МКД dp.include_router(admin_router) dp.include_router(users_router) other_routers = [ verification_router, chat_monitor_router, security_router, apartments_router, antimat_router, phones_router, polls_router, antispam_router, ratelimit_router, schedule_router, ads_router, payments_router, multicount_router, topics_router, toxicity_router, profile_history_router, achievements_router, thanks_router, events_router, initiative_group_router, mutual_aid_router ] for r in other_routers: dp.include_router(r) from handlers.smart_broadcast import router as smart_broadcast_router from handlers.digest import router as digest_router from handlers.legal_advisor import router as legal_advisor_router dp.include_router(legal_advisor_router) dp.include_router(smart_broadcast_router) dp.include_router(digest_router) dp.startup.register(on_startup) logger.info('🤖 Бот запускается...') await dp.start_polling(bot) if __name__ == '__main__': try: asyncio.run(main()) except KeyboardInterrupt: logger.info('🛑 Остановка пользователем.') except Exception as e: logger.error(f'Критическая ошибка: {e}', exc_info=True)