56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
from storage import Profile, scan
|
||
from 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)
|