import asyncio import logging from aiogram import executor import filters import handlers from load import dp, config from utils.updater import updater skip_updates=True logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) async def on_startup(dp): webhook_url = "{host}{path}{token}".format( host=config["WebHook"]["webhook_host"], path=config["WebHook"]["webhook_path"], token=config["Bot"]["token"] ) await dp.bot.set_webhook(url=webhook_url) async def on_shutdown(dp): await dp.bot.delete_webhook() if __name__ == "__main__": loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.create_task(updater()) if config["WebHook"]["use"].lower() in ["yes", "true"]: # https://github.com/aiogram/aiogram/pull/795/commits/a7e0ce2971a0a320849c8b11080fa6b737b6935b # Needed for async tasks :3 # Only for webhooks! For polling not needed patching file executor.start_webhook( dispatcher=dp, loop=loop, skip_updates=skip_updates, webhook_path="{}{}".format(config["WebHook"]["webhook_path"], config["Bot"]["token"]), on_startup=on_startup, on_shutdown=on_shutdown, host=config["WebHook"]["app_host"], port=config["WebHook"]["app_port"] ) else: executor.start_polling(dp, skip_updates=skip_updates)