#!/usr/bin/env python3 """ 🏠 Домовой Бот — Telegram-бот для чата многоквартирного дома ВЕРСИЯ: v4.0 — REBORN (LKM37 CORE) ДАТА ФИКСАЦИИ: 17 апреля 2026 г. СТАТУС: ✅ АКТИВИРОВАН НОВОЕ В v4.0: - ✅ Единый стиль LKM37 (Slate & Cyan) - ✅ Стабильное меню (Grid 2xN) - ✅ Маркет 2.0 (Фото + Категории) - ✅ SpyDetector 2.0 (Анализ токсичности) - ✅ Взаимовыручка соседей (Neighbor Aid) - ✅ Авто-Дайджест с подтверждением - ✅ Матричная веб-панель """ import logging import asyncio import sys from pathlib import Path # Добавляем путь к проекту BASE_DIR = Path(__file__).resolve().parent sys.path.insert(0, str(BASE_DIR)) from aiogram import Bot, Dispatcher from aiogram.client.default import DefaultBotProperties from aiogram.enums import ParseMode from aiogram.filters import Command from aiogram.types import Message from aiogram.client.session.aiohttp import AiohttpSession from aiogram.fsm.storage.memory import MemoryStorage from config import ( BOT_TOKEN, ADMIN_USER_ID, ADMIN_CHAT_ID, get_proxy_url, USE_PROXY, PROXY_TYPE, PROXY_HOST, PROXY_PORT ) 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.web_server import WebServerService from database.models import ScheduledPost # Настройка логирования 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() ] ) import os logger = logging.getLogger(__name__) # МАРКЕР ЗАПУСКА БОТА logger.info(f"!!! [STARTUP] main.py execution started. PID: {os.getpid()}") async def on_startup(bot: Bot): """Действия при запуске""" logger.info(f"!!! [STARTUP] on_startup triggered. PID: {os.getpid()}") logger.info('🚀 LKM37 CORE v4.0 запускается...') await init_db() scheduler = Scheduler(bot) scheduler.start() # Веб-сервер теперь запускается отдельным сервисом (domovoy-web.service) # web_server = WebServerService(port=8000) # web_server.start() try: await bot.send_message( ADMIN_USER_ID, '✅ LKM37 CORE v4.0 АКТИВИРОВАН\n\n' 'Система переведена в режим REBORN.\n' 'Все модули стабильны.', parse_mode=ParseMode.HTML ) except Exception as e: logger.error(f'Ошибка уведомления админа: {e}') async def main(): from bot_instance import get_bot bot = get_bot() dp = Dispatcher(storage=MemoryStorage()) # Регистрация роутеров routers = [ 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, mutual_aid_router ] for r in routers: dp.include_router(r) from handlers.smart_broadcast import router as smart_broadcast_router from handlers.digest import router as digest_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)