dokku-comp

This commit is contained in:
2023-09-11 23:04:53 +03:00
parent 4be2dc3a45
commit b9a98f1e56
25 changed files with 646 additions and 460 deletions

View File

@@ -2,52 +2,49 @@ from bot.api import send_message, send_photo, get_userphotos
from bot.utils.mention import mention, userdata_extract
from bot.storage import storage
def show_request_msg(msg):
async def show_request_msg(msg):
print("showing request with button")
chat_id = str(msg['chat']['id'])
from_id = str(msg['from']['id'])
lang = msg['from'].get('language_code', 'ru')
chat_id = str(msg["chat"]["id"])
from_id = str(msg["from"]["id"])
lang = msg["from"].get("language_code", "ru")
reply_markup = {
"inline_keyboard": [
[
{
"text": '❤️',
"callback_data": 'vouch' + from_id
}
]
]
"inline_keyboard": [[{"text": "❤️", "callback_data": "vouch" + from_id}]]
}
newcomer_message = "Нажмите, чтобы одобрить заявку " if lang == 'ru' \
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)
)
r = await get_userphotos(user_id=from_id)
print(r)
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'])
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"])
r = send_photo(
chat_id,
file_id,
caption=newcomer_message + f'{identity}{username}',
reply_to=msg.get('message_id', ''),
reply_markup=reply_markup
caption=newcomer_message + f"{identity}{username}",
reply_to=msg.get("message_id", ""),
reply_markup=reply_markup,
)
else:
print('show button without photo')
print("show button without photo")
r = send_message(
chat_id,
newcomer_message + mention(msg['from']),
reply_to=msg.get('message_id', ''),
reply_markup=reply_markup
newcomer_message + mention(msg["from"]),
reply_to=msg.get("message_id", ""),
reply_markup=reply_markup,
)
print(r)
if 'message_id' in r:
if "message_id" in r:
# удаляем предыдущее сообщение с кнопкой в этом чате
prevbtn = storage.get(f'btn-{chat_id}-{from_id}')
prevbtn = storage.get(f"btn-{chat_id}-{from_id}")
if prevbtn:
r = delete_message(chat_id, prevbtn)
r = await 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)
newbtn = r["message_id"]
print(f"button message id: {newbtn}")
storage.set(f"btn-{chat_id}-{from_id}", newbtn)