-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
48 lines (34 loc) · 1.27 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import asyncio
from aiogram import Dispatcher, Bot
from aiogram.enums import ParseMode
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.client.default import DefaultBotProperties
from dishka.integrations.aiogram import setup_dishka
from src.ioc import container
from src.settings import BotConfig
from src.aspects import register_aspects
from src.database.postgres.migrations import create_tables
from src.controllers.bot_routes import bot_router, form_router
async def main():
dp = Dispatcher(storage=MemoryStorage())
bot = Bot(
token=BotConfig.token,
default=DefaultBotProperties(parse_mode=ParseMode.HTML)
)
# Создаем таблицы
await create_tables()
# Регистрируем аспекты
register_aspects(bot_router)
# Регистрируем обработчики
dp.include_router(bot_router)
# Регистрируем роутер для регистрации (чтобы обойти Middleware)
dp.include_router(form_router)
# Внедряем IoC
setup_dishka(container=container, router=dp)
try:
await dp.start_polling(bot)
finally:
await container.close()
await bot.session.close()
if __name__ == "__main__":
asyncio.run(main())