UdoChudo 553942425e
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m35s
fix: Move main file to root of project, now start correctly
2025-08-31 22:24:56 +05:00

62 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
from aiogram.filters import Command
from bot.core.bot import create_bot, create_dispatcher
from bot.services.xui import XUIService
from bot.services.client import ClientService
from bot.handlers.base import cmd_start, cmd_help
from bot.handlers.client import ClientHandlers
from bot.filters.access import AllowedUsersFilter
from bot.utils.logging import logger
async def setup_handlers(dp, client_handlers: ClientHandlers):
"""Настройка обработчиков команд."""
# Базовые команды (доступны всем)
dp.message.register(cmd_start, Command(commands=["start"]))
dp.message.register(cmd_help, Command(commands=["help"]))
# Команды для работы с клиентами (только для разрешенных пользователей)
dp.message.register(
client_handlers.cmd_create,
Command(commands=["create"]),
AllowedUsersFilter()
)
dp.message.register(
client_handlers.cmd_info,
Command(commands=["info"]),
AllowedUsersFilter()
)
async def main():
"""Главная функция приложения."""
logger.info("Запуск бота...")
# Создаем основные компоненты
bot = create_bot()
dp = create_dispatcher()
# Создаем сервисы
xui_service = XUIService()
client_service = ClientService(xui_service)
# Создаем обработчики
client_handlers = ClientHandlers(client_service)
# Настраиваем обработчики
await setup_handlers(dp, client_handlers)
try:
logger.info("Бот запущен и готов к работе")
await dp.start_polling(bot)
except Exception as e:
logger.error(f"Ошибка при запуске бота: {e}")
raise
finally:
await bot.session.close()
logger.info("Бот остановлен")
if __name__ == "__main__":
asyncio.run(main())