-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (36 loc) · 1.18 KB
/
main.py
File metadata and controls
47 lines (36 loc) · 1.18 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
40
41
42
43
44
45
46
47
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.fsm.storage.redis import RedisStorage
from app.db.models import async_main
from app.db.redis.redis_client import redis
from app.handlers import register_all_handlers
from config import API_TOKEN
# Set up logging configuration for the entire application
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
async def main():
"""
Main entry point for the bot application.
Initializes all necessary components and starts the bot.
"""
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(storage=RedisStorage(redis), bot=bot)
# Register all message and callback handlers
register_all_handlers(dp)
# Initialize database and create tables if they don't exist
await async_main()
logger.info("Starting bot...")
try:
await dp.start_polling(bot)
except Exception as e:
logger.error(f"Critical error during bot execution: {e}")
raise
finally:
await bot.session.close()
if __name__ == '__main__':
asyncio.run(main())