clash-telegram-bot/bot.py

53 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-03-19 00:58:59 +03:00
import asyncio
2022-03-18 22:25:50 +03:00
import logging
from aiogram import executor
import filters
import handlers
2022-03-19 00:58:59 +03:00
from load import dp, config
from utils.updater import updater
2022-03-18 22:25:50 +03:00
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__":
2022-03-19 00:58:59 +03:00
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_task(updater())
2022-03-18 22:25:50 +03:00
if config["WebHook"]["use"].lower() in ["yes", "true"]:
2022-03-19 00:58:59 +03:00
# https://github.com/aiogram/aiogram/pull/795/commits/a7e0ce2971a0a320849c8b11080fa6b737b6935b
# Needed for async tasks :3
# Only for webhooks! For polling not needed patching file
2022-03-18 22:25:50 +03:00
executor.start_webhook(
dispatcher=dp,
2022-03-19 00:58:59 +03:00
loop=loop,
2022-03-18 22:25:50 +03:00
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)