version-0.2.0

This commit is contained in:
2024-01-06 14:25:35 +03:00
parent bc05b93c47
commit 908529b5bb
26 changed files with 185 additions and 153 deletions

55
handlers/command_my.py Normal file
View File

@@ -0,0 +1,55 @@
from storage import Profile, scan
from bot.api import get_member, send_message
from utils.mention import userdata_extract
import json
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def construct_unlink_buttons(actor):
print(f"constructing unlink buttons for {actor['children']}")
buttons = []
for vouch in actor["children"]:
for chat_id in actor["chats"]:
r = await get_member(chat_id, vouch)
logger.debug(r)
if "result" in r:
member = r["result"]["user"]
_uid, identity, username = userdata_extract(member)
buttons.append(
{"text": f"{identity} {username}", "callback_data": "unlink" + vouch}
)
return buttons
async def handle_command_my(msg, state):
logger.info("handle my command")
from_id = str(msg["from"]["id"])
sender = Profile.get(from_id, msg)
# генерируем кнопки для всех, за кого поручились
buttons = await construct_unlink_buttons(sender)
reply_markup = {
"inline_keyboard": [
buttons,
]
}
if len(buttons) == 0:
if msg["from"].get("language_code", "ru") == "ru":
body = "Вас ещё никто не узнал? Напишите, я передам нашему кругу"
else:
body = (
"Nobody recognized you? Speak, I will pass your message to the circle"
)
r = await send_message(from_id, body)
logger.debug(r)
chat_id = msg["chat"]["id"]
state.make_talking(from_id, chat_id)
else:
if msg["from"].get("language_code", "ru") == "ru":
body = "Нажмите кнопки ниже, чтобы удалить ваши связи"
else:
body = "Unlink your connections pressing the buttons below"
r = await send_message(from_id, body, reply_markup=reply_markup)
print(r)