welcomecenterbot/tgbot/handlers/send_button.py

50 lines
1.8 KiB
Python
Raw Normal View History

2023-04-28 12:24:14 +00:00
from tgbot.api import send_message, send_photo, get_userphotos
2023-04-24 06:14:35 +00:00
from tgbot.utils.mention import mention
2023-04-28 12:24:14 +00:00
from tgbot.storage import storage
2023-04-23 16:54:58 +00:00
def show_request_msg(msg):
2023-04-28 12:24:14 +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 = {
"inline_keyboard": [
[
{
2023-04-28 12:24:14 +00:00
"text": 'Моё одобрение' if lang == 'ru' else 'My connection',
"callback_data": 'vouch' + from_id
2023-04-23 16:54:58 +00:00
}
]
]
}
2023-04-28 12:24:14 +00:00
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)