GPQBot
1from functools import partial
2
3from fastapi import FastAPI
4from pybotx import Bot
5
6from db.sqlalchemy import build_db_session_factory
7from dependencies.bot import get_bot
8from api.routers import router
9
10async def startup(bot: Bot) -> None:
11# -- Bot --
12await bot.startup()
13
14# -- Database --
15bot.state.db_session_factory = await build_db_session_factory()
16
17
18
19async def shutdown(application: FastAPI) -> None:
20bot: Bot = application.state.bot
21await bot.shutdown()
22
23def get_application() -> FastAPI:
24"""Create configured server application instance."""
25bot = get_bot()
26
27application = FastAPI(title='BOT')
28application.state.bot = bot
29
30application.add_event_handler("startup", partial(startup, bot))
31application.add_event_handler("shutdown", partial(shutdown, bot))
32
33application.include_router(router)
34
35return application
36
37
38app = get_application()