-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (32 loc) · 963 Bytes
/
main.py
File metadata and controls
41 lines (32 loc) · 963 Bytes
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
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from config import Config
from database import Database
from handlers import router
from background_tasks import BackgroundTaskManager
async def main():
"""Main function to start the bot"""
config = Config()
db = Database()
await db.init_db()
bot = Bot(
token=config.BOT_TOKEN,
default=DefaultBotProperties(parse_mode=ParseMode.HTML)
)
dp = Dispatcher()
dp.include_router(router)
dp["db"] = db
dp["config"] = config
# Start background tasks
task_manager = BackgroundTaskManager(db, config)
await task_manager.start()
try:
await dp.start_polling(bot)
finally:
await task_manager.stop()
await bot.session.close()
await db.close()
if __name__ == "__main__":
asyncio.run(main())