-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (31 loc) · 1.07 KB
/
main.py
File metadata and controls
42 lines (31 loc) · 1.07 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
import asyncio
from aiohttp import web
from app.commands import set_default_commands
from app.handlers import setup_handlers
from app.middlewares import setup_middlewares
from core.config import tgbot
from core.loader import bot, dp
from core.webhook import run_polling, run_webhook
from utils.logging import logger
async def on_startup() -> None:
"""Действия при запуске бота."""
if tgbot.SET_COMMANDS:
await set_default_commands()
logger.log("BOT", "~ Bot startup")
async def on_shutdown() -> None:
"""Действия при остановке бота."""
logger.log("BOT", "~ Bot shutting down...")
await bot.session.close()
async def main():
"""Главная функция запуска бота."""
setup_middlewares(dp)
setup_handlers(dp)
dp.startup.register(on_startup)
dp.shutdown.register(on_shutdown)
if tgbot.IS_WEBHOOK:
app = web.Application()
await run_webhook(app, bot, dp)
else:
await run_polling(bot, dp)
if __name__ == "__main__":
asyncio.run(main())