generated from welel/aiogram-bot-template
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbot.py
43 lines (31 loc) · 1011 Bytes
/
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
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from src.config import configs
from src.handlers import user_handlers
logger = logging.getLogger(__name__)
async def main():
if configs.tg_bot.debug_mode:
logging_level = logging.DEBUG
else:
logging_level = logging.INFO
logging.basicConfig(
level=logging_level,
format="%(filename)s:%(lineno)d #%(levelname)-8s "
"[%(asctime)s] - %(name)s - %(message)s",
)
logger.info("Starting bot...")
bot: Bot = Bot(
token=configs.tg_bot.token,
default=DefaultBotProperties(parse_mode="HTML"),
)
dp: Dispatcher = Dispatcher()
dp.include_router(user_handlers.router)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.info("Bot stopped.")