-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (30 loc) · 1.06 KB
/
main.py
File metadata and controls
39 lines (30 loc) · 1.06 KB
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
import asyncio
import logging
import sys
from aiogram import Bot, Dispatcher
from aiogram.fsm.storage.memory import MemoryStorage
from pyvnytsya_bot.config import config
from pyvnytsya_bot.handlers import common, menu, game
from pyvnytsya_bot.database.engine import init_db, async_session
from pyvnytsya_bot.middlewares.db import DbSessionMiddleware
async def main():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
)
# Initialize DB
await init_db()
bot = Bot(token=config.BOT_TOKEN.get_secret_value())
dp = Dispatcher(storage=MemoryStorage())
# Middlewares
dp.update.middleware(DbSessionMiddleware(session_pool=async_session))
# Routers
dp.include_router(common.router)
dp.include_router(menu.router)
dp.include_router(game.router)
logging.info("Bot started!")
await dp.start_polling(bot)
if __name__ == "__main__":
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())