-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
47 lines (33 loc) · 1.23 KB
/
bot.py
File metadata and controls
47 lines (33 loc) · 1.23 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.client.default import DefaultBotProperties
from config_data.config import load_config
from handlers import user_handlers
from keyboards.set_menu import set_main_menu
from states import user_states
from models.models import Base
from models.methods import engine
logger = logging.getLogger(__name__)
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')
config = load_config(r'.env')
bot: Bot = Bot(token=config.tg_bot.token,
default=DefaultBotProperties(parse_mode='HTML'))
dp: Dispatcher = Dispatcher(storage=user_states.storage)
await bot.delete_my_commands()
await set_main_menu(bot)
dp.include_router(user_handlers.router)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == '__main__':
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logger.error('Bot stopped')