mirror of
https://github.com/civsocit/olgram.git
synced 2025-12-15 08:16:17 +00:00
регистрация токенов
This commit is contained in:
34
server/server.py
Normal file
34
server/server.py
Normal 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()
|
||||
Reference in New Issue
Block a user