domovoy_bot/main.py

98 lines
3.3 KiB
Python

#!/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.voice import voice_router
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
# Настройка логирования
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, '✅ <b>LKM37 CORE v4.3 АКТИВИРОВАН</b>')
except: pass
async def main():
from bot_instance import get_bot
bot = get_bot()
dp = Dispatcher(storage=MemoryStorage())
# КРИТИЧЕСКИ ВАЖНО: voice_router должен быть САМЫМ ПЕРВЫМ
dp.include_router(voice_router)
# Регистрация остальных
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.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)
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)