mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
35 lines
806 B
Python
35 lines
806 B
Python
from aiogram import Bot
|
|
import hashlib
|
|
|
|
from olgram.settings import ServerSettings
|
|
|
|
|
|
def path_for_bot(token: str) -> str:
|
|
return "/" + hashlib.md5(token.encode("UTF-8")).hexdigest()
|
|
|
|
|
|
def url_for_bot(token: str) -> str:
|
|
return f"https://{ServerSettings.hook_host()}:{ServerSettings.hook_port()}" + path_for_bot(token)
|
|
|
|
|
|
async def register_token(token: str) -> bool:
|
|
"""
|
|
Зарегистрировать токен
|
|
:param token: токен
|
|
:return: получилось ли
|
|
"""
|
|
bot = Bot(token)
|
|
res = await bot.set_webhook(url_for_bot(token))
|
|
await bot.session.close()
|
|
return res
|
|
|
|
|
|
async def unregister_token(token: str):
|
|
"""
|
|
Удалить токен
|
|
:param token: токен
|
|
:return:
|
|
"""
|
|
bot = Bot(token)
|
|
await bot.delete_webhook()
|