2023-09-11 15:52:35 +00:00
|
|
|
|
from bot.api import send_message, send_photo, get_userphotos
|
|
|
|
|
from bot.utils.mention import mention, userdata_extract
|
|
|
|
|
from bot.storage import storage
|
2023-04-23 16:54:58 +00:00
|
|
|
|
|
2023-09-11 20:04:53 +00:00
|
|
|
|
|
|
|
|
|
async def show_request_msg(msg):
|
2023-09-11 17:02:29 +00:00
|
|
|
|
print("showing request with button")
|
2023-09-11 20:04:53 +00:00
|
|
|
|
chat_id = str(msg["chat"]["id"])
|
|
|
|
|
from_id = str(msg["from"]["id"])
|
|
|
|
|
lang = msg["from"].get("language_code", "ru")
|
2023-04-23 16:54:58 +00:00
|
|
|
|
reply_markup = {
|
2023-09-11 20:04:53 +00:00
|
|
|
|
"inline_keyboard": [[{"text": "❤️", "callback_data": "vouch" + from_id}]]
|
2023-04-23 16:54:58 +00:00
|
|
|
|
}
|
2023-09-11 20:04:53 +00:00
|
|
|
|
newcomer_message = (
|
|
|
|
|
"Нажмите, чтобы одобрить заявку "
|
|
|
|
|
if lang == "ru"
|
2023-04-28 12:24:14 +00:00
|
|
|
|
else "There is a newcomer, press the button if you are connected with "
|
2023-09-11 20:04:53 +00:00
|
|
|
|
)
|
|
|
|
|
r = await get_userphotos(user_id=from_id)
|
2023-04-28 12:24:14 +00:00
|
|
|
|
print(r)
|
2023-09-11 20:04:53 +00:00
|
|
|
|
if r["ok"] and r["result"]["total_count"] > 0:
|
|
|
|
|
print("show button with photo")
|
|
|
|
|
file_id = r["result"]["photos"][0][0]["file_id"]
|
|
|
|
|
_uid, identity, username = userdata_extract(msg["from"])
|
2023-04-28 12:24:14 +00:00
|
|
|
|
r = send_photo(
|
|
|
|
|
chat_id,
|
|
|
|
|
file_id,
|
2023-09-11 20:04:53 +00:00
|
|
|
|
caption=newcomer_message + f"{identity}{username}",
|
|
|
|
|
reply_to=msg.get("message_id", ""),
|
|
|
|
|
reply_markup=reply_markup,
|
2023-04-28 12:24:14 +00:00
|
|
|
|
)
|
|
|
|
|
else:
|
2023-09-11 20:04:53 +00:00
|
|
|
|
print("show button without photo")
|
2023-09-06 10:11:40 +00:00
|
|
|
|
r = send_message(
|
2023-04-28 12:24:14 +00:00
|
|
|
|
chat_id,
|
2023-09-11 20:04:53 +00:00
|
|
|
|
newcomer_message + mention(msg["from"]),
|
|
|
|
|
reply_to=msg.get("message_id", ""),
|
|
|
|
|
reply_markup=reply_markup,
|
2023-04-28 12:24:14 +00:00
|
|
|
|
)
|
|
|
|
|
print(r)
|
2023-09-11 20:04:53 +00:00
|
|
|
|
if "message_id" in r:
|
2023-04-28 12:24:14 +00:00
|
|
|
|
# удаляем предыдущее сообщение с кнопкой в этом чате
|
2023-09-11 20:04:53 +00:00
|
|
|
|
prevbtn = storage.get(f"btn-{chat_id}-{from_id}")
|
2023-04-28 12:24:14 +00:00
|
|
|
|
if prevbtn:
|
2023-09-11 20:04:53 +00:00
|
|
|
|
r = await delete_message(chat_id, prevbtn)
|
2023-04-28 12:24:14 +00:00
|
|
|
|
print(r)
|
|
|
|
|
# создаём новое
|
2023-09-11 20:04:53 +00:00
|
|
|
|
newbtn = r["message_id"]
|
|
|
|
|
print(f"button message id: {newbtn}")
|
|
|
|
|
storage.set(f"btn-{chat_id}-{from_id}", newbtn)
|