1
0
mirror of https://github.com/civsocit/olgram.git synced 2025-12-15 08:16:17 +00:00

регистрация токенов

This commit is contained in:
mihalin
2021-09-09 20:38:33 +03:00
parent 869df66cd3
commit bf7c18c076
4 changed files with 50 additions and 0 deletions

34
server/server.py Normal file
View File

@@ -0,0 +1,34 @@
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()