mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Починка статусов в ботов5
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
"""Bot initialization module"""
|
"""Bot initialization module"""
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from .config import settings
|
from .config import settings
|
||||||
|
from .handlers import callbacks_router, start_router
|
||||||
|
|
||||||
# Initialize bot and dispatcher
|
# Initialize bot and dispatcher
|
||||||
bot = Bot(token=settings.bot_token)
|
bot = Bot(token=settings.bot_token)
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
|
|
||||||
|
# Include routers only once during initialization
|
||||||
|
dp.include_router(callbacks_router)
|
||||||
|
dp.include_router(start_router)
|
||||||
|
|
||||||
async def start_bot():
|
async def start_bot():
|
||||||
"""Start the bot and include all routers"""
|
"""Start the bot"""
|
||||||
from .handlers import callbacks_router, start_router
|
try:
|
||||||
|
await dp.start_polling(bot, skip_updates=True)
|
||||||
# Include routers
|
except Exception as e:
|
||||||
dp.include_router(callbacks_router)
|
print(f"Error starting bot: {e}")
|
||||||
dp.include_router(start_router)
|
|
||||||
|
|
||||||
# Start polling
|
|
||||||
await dp.start_polling(bot, skip_updates=True)
|
|
@@ -10,25 +10,29 @@ from logging import getLogger
|
|||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
async def run_bot():
|
|
||||||
"""Run Telegram bot"""
|
|
||||||
try:
|
|
||||||
await start_bot()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Bot crashed: {e}", exc_info=True)
|
|
||||||
|
|
||||||
async def run_api():
|
async def run_api():
|
||||||
"""Run FastAPI application"""
|
"""Run FastAPI application"""
|
||||||
config = uvicorn.Config(app, host="0.0.0.0", port=8000, reload=True)
|
config = uvicorn.Config(
|
||||||
|
app,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
reload=True
|
||||||
|
)
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
try:
|
await server.serve()
|
||||||
await server.serve()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"API crashed: {e}", exc_info=True)
|
|
||||||
|
|
||||||
async def run_all():
|
async def main():
|
||||||
"""Run both bot and API"""
|
"""Run both bot and API in the main thread"""
|
||||||
await asyncio.gather(run_bot(), run_api())
|
try:
|
||||||
|
# Создаем задачи для бота и API
|
||||||
|
bot_task = asyncio.create_task(start_bot())
|
||||||
|
api_task = asyncio.create_task(run_api())
|
||||||
|
|
||||||
|
# Запускаем обе задачи
|
||||||
|
await asyncio.gather(bot_task, api_task)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Application crashed: {e}", exc_info=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(run_all())
|
# Запускаем в основном потоке
|
||||||
|
asyncio.run(main())
|
Reference in New Issue
Block a user