74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
import asyncio
|
||
import logging
|
||
|
||
from aiogram import Bot, Dispatcher
|
||
from aiogram.client.default import DefaultBotProperties
|
||
from aiogram.enums import ParseMode
|
||
from aiogram.types import BotCommand
|
||
|
||
from config.settings import settings
|
||
from bot.handlers import start, vocabulary, tasks, settings as settings_handler, words, import_text, practice, reminder, level_test
|
||
from database.db import init_db
|
||
from services.reminder_service import init_reminder_service
|
||
|
||
|
||
async def main():
|
||
"""Главная функция запуска бота"""
|
||
# Настройка логирования
|
||
logging.basicConfig(
|
||
level=logging.INFO if settings.debug else logging.WARNING,
|
||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||
)
|
||
|
||
# Инициализация бота и диспетчера
|
||
bot = Bot(
|
||
token=settings.bot_token,
|
||
default=DefaultBotProperties(parse_mode=ParseMode.HTML)
|
||
)
|
||
dp = Dispatcher()
|
||
|
||
# Команды бота для меню Telegram
|
||
await bot.set_my_commands([
|
||
BotCommand(command="start", description="Запустить бота"),
|
||
BotCommand(command="add", description="Добавить слово"),
|
||
BotCommand(command="words", description="Тематическая подборка слов"),
|
||
BotCommand(command="import", description="Импорт слов из текста"),
|
||
BotCommand(command="vocabulary", description="Мой словарь"),
|
||
BotCommand(command="task", description="Задания"),
|
||
BotCommand(command="practice", description="Диалог с AI"),
|
||
BotCommand(command="stats", description="Статистика"),
|
||
BotCommand(command="settings", description="Настройки"),
|
||
BotCommand(command="reminder", description="Напоминания"),
|
||
BotCommand(command="help", description="Справка"),
|
||
])
|
||
|
||
# Регистрация роутеров
|
||
dp.include_router(start.router)
|
||
dp.include_router(level_test.router)
|
||
dp.include_router(vocabulary.router)
|
||
dp.include_router(tasks.router)
|
||
dp.include_router(settings_handler.router)
|
||
dp.include_router(words.router)
|
||
dp.include_router(import_text.router)
|
||
dp.include_router(practice.router)
|
||
dp.include_router(reminder.router)
|
||
|
||
# Инициализация базы данных
|
||
await init_db()
|
||
|
||
# Инициализация и запуск сервиса напоминаний
|
||
reminder_service = init_reminder_service(bot)
|
||
reminder_service.start()
|
||
|
||
# Запуск бота
|
||
logging.info("Бот запущен")
|
||
try:
|
||
await dp.start_polling(bot)
|
||
finally:
|
||
# Остановка планировщика при завершении
|
||
reminder_service.shutdown()
|
||
|
||
|
||
if __name__ == '__main__':
|
||
asyncio.run(main())
|