This commit is contained in:
2023-04-28 15:24:14 +03:00
parent 351b53f007
commit 318b24243a
20 changed files with 244 additions and 154 deletions

View File

@@ -1,25 +1,49 @@
from tgbot.api import send_message
from tgbot.config import BUTTON_VOUCH, NEWCOMER_MSG
from tgbot.api import send_message, send_photo, get_userphotos
from tgbot.utils.mention import mention
from tgbot.storage import storage
def show_request_msg(msg):
chat_id = str(msg['chat']['id'])
from_id = str(msg['from']['id'])
lang = msg['from'].get('language_code', 'ru')
reply_markup = {
"inline_keyboard": [
[
{
"text": BUTTON_VOUCH,
"callback_data": BUTTON_VOUCH + str(msg['from']['id'])
"text": 'Моё одобрение' if lang == 'ru' else 'My connection',
"callback_data": 'vouch' + from_id
}
]
]
}
r = send_message(
msg['chat']['id'],
NEWCOMER_MSG + mention(msg['from']),
reply_to=msg.get('message_id', ''),
reply_markup=reply_markup
)
btn_msg_id = r['result']['message_id']
print(f'request message id: {btn_msg_id}')
return btn_msg_id
newcomer_message = "Нажмите, чтобы одобрить заявку " if lang == 'ru' \
else "There is a newcomer, press the button if you are connected with "
r = get_userphotos(user_id=from_id)
print(r)
if r['ok'] and r['result']['total_count'] > 0:
file_id = r['result']['photos'][0][0]['file_id']
r = send_photo(
chat_id,
file_id,
caption=newcomer_message + mention(msg['from']),
reply_to=msg.get('message_id', ''),
reply_markup=reply_markup
)
else:
r = send_photo(
chat_id,
newcomer_message + mention(msg['from']),
reply_to=msg.get('message_id', ''),
reply_markup=reply_markup
)
print(r)
if 'message_id' in r:
# удаляем предыдущее сообщение с кнопкой в этом чате
prevbtn = storage.get(f'btn-{chat_id}-{from_id}')
if prevbtn:
r = delete_message(chat_id, prevbtn)
print(r)
# создаём новое
newbtn = r['message_id']
print(f'button message id: {newbtn}')
storage.set(f'btn-{chat_id}-{from_id}', newbtn)