-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
43 lines (35 loc) · 1.32 KB
/
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.contrib.fsm_storage.redis import RedisStorage2
from config_data.config import Config, load_config
from keyboards.main_menu import set_main_menu
from handlers.user_handlers import register_user_handlers
from handlers.game_handlers import register_game_handlers
from handlers.other_handlers import register_spam_handler
logger = logging.getLogger(__name__)
def register_all_handlers(dp: Dispatcher) -> None:
register_user_handlers(dp)
register_game_handlers(dp)
register_spam_handler(dp)
async def main():
logging.basicConfig(
level=logging.INFO,
format=u'%(filename)s:%(lineno)d #%(levelname)-8s '
u'[%(asctime)s] - %(name)s - %(message)s')
logger.info('Starting bot')
storage: RedisStorage2 = RedisStorage2('localhost', 6379, db=0)
config: Config = load_config()
bot: Bot = Bot(token=config.tg_bot.token, parse_mode='HTML')
dp: Dispatcher = Dispatcher(bot, storage=storage)
await set_main_menu(dp)
register_all_handlers(dp)
try:
await dp.start_polling()
finally:
await bot.close()
if __name__ == '__main__':
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.error('Bot stopped!')