-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
38 lines (23 loc) · 939 Bytes
/
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
from aiogram import Dispatcher
from aiogram import executor
from bot.commands import set_default_commands
from loader import dp, bot, config
from models.base import create_async_database
from utils.misc.logging import logger
async def on_startup(dispatcher: Dispatcher):
logger.info('Bot startup')
bot['session'] = await create_async_database()
for admin_id in config.ADMINS:
await bot.send_message(admin_id, 'bot started')
await set_default_commands()
async def on_shutdown(dispatcher: Dispatcher):
logger.warning('Shutting down..')
await dp.storage.close()
await dp.storage.wait_closed()
await dp.bot.get('session').close()
logger.warning('Bye!')
if __name__ == '__main__':
from bot.middlewares import setup_middleware
from bot import filters, handlers
setup_middleware(dp)
executor.start_polling(dp, on_startup=on_startup)