forked from FOSS/ASF-Control-Bot
feat(bot): add async DB and FSM state handling
This commit is contained in:
@@ -2,9 +2,11 @@ import asyncio
|
||||
import logging
|
||||
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.fsm.storage.memory import MemoryStorage
|
||||
from aiogram.client.default import DefaultBotProperties
|
||||
|
||||
from bot.config import BOT_TOKEN
|
||||
from bot.db.init import init_db
|
||||
|
||||
from bot.handlers.bots import router as bots_router
|
||||
from bot.handlers.console import router as console_router
|
||||
@@ -18,7 +20,7 @@ from bot.handlers.twofa import router as twofa_router
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode="HTML")) # type: ignore[arg-type]
|
||||
dp = Dispatcher()
|
||||
dp = Dispatcher(storage=MemoryStorage())
|
||||
|
||||
dp.include_router(start_router)
|
||||
dp.include_router(navigation_router)
|
||||
@@ -31,6 +33,7 @@ dp.include_router(messages_router)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await init_db()
|
||||
await dp.start_polling(bot)
|
||||
|
||||
|
||||
@@ -43,10 +46,13 @@ if __name__ == "__main__":
|
||||
logging.StreamHandler(),
|
||||
],
|
||||
)
|
||||
|
||||
try:
|
||||
asyncio.run(main())
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Получен сигнал остановки, бот завершает работу")
|
||||
|
||||
except Exception:
|
||||
logger.exception("Бот завершился из-за необработанной ошибки")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user