-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (36 loc) · 1.22 KB
/
app.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
import asyncio
import logging
from aiogram import Bot, Dispatcher
from config_data.config import Config, load_config
from handlers.handlers import register_user_handlers
from handlers.other_handlers import register_other_handlers
# Initialize logger
logger = logging.getLogger(__name__)
def register_all_handlers(dp: Dispatcher) -> None:
register_user_handlers(dp)
register_other_handlers(dp)
async def main():
# Configure logging
logging.basicConfig(
level=logging.INFO,
format=u'%(filename)s:%(lineno)d #%(levelname)-8s '
u'[%(asctime)s] - %(name)s - %(message)s')
# Print the info about starting the bot
logger.info('Starting bot')
# Load configuration in config variable
config: Config = load_config()
# Initialize bot and dispatcher
bot: Bot = Bot(token=config.tg_bot.token, parse_mode="HTML")
dp: Dispatcher = Dispatcher(bot)
# Register all handlers
register_all_handlers(dp)
# Load polling
try:
await dp.start_polling()
finally:
await bot.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.error('Bot stopped!')