Reapply after left the chat: WIP

This commit is contained in:
Profitroll 2022-12-05 14:38:18 +01:00
parent 7de55e950e
commit 1c0c8fa8c4
2 changed files with 71 additions and 9 deletions

View File

@ -44,7 +44,8 @@
"sus_allowed_by": "✅ **Доступ дозволено**\nАдмін **{0}** дозволив `{1}` вступити до спільноти не за персональним посиланням.",
"sus_refused_by": "❌ **Доступ заборонено**\nАдмін **{0}** заборонив `{1}` доступ до спільноти не за персональним посиланням.",
"reapply_forbidden": "❌ **Дія неможлива**\nТвоя минула анкета ще не була схвалена або відхилена.",
"reapply_in_progress": "❌ **Дія неможлива**\nТи прямо зараз вже заповнюєш анкету. Якщо в ній є помилка - після заповнення просто натисни **{0}** та почни знову.",
"reapply_in_progress": "❌ **Дія неможлива**\nТи прямо зараз вже заповнюєш анкету. Якщо в ній є помилка - просто натисни кнопку нижче щоб почати заповнювати спочатку.",
"reapply_left_chat": "⚠️ **Нагадування**\nЗдається, ти залишив чат у минулому, проте твоя анкета все ще доступна до використання. Подати запит на вступ користуючись старою анкетою?",
"birthday": "У користувача **{0}** (@{1}) сьогодні день народження! Виповнилось {2} років",
"application_invalid_syntax": "Неправильний синтаксис!\nТреба: `/application ID/NAME/USERNAME`",
"warned": "Попереджено користувача **{0}** (`{1}`) про порушення правил",
@ -118,10 +119,13 @@
"sus_refused": "❌ Користувача заблоковано",
"reapply_yes": "✅ Прийняти",
"reapply_no": "❌ Відхилити",
"reapply_old_one": "✅ Надіслати стару",
"reapply_new_one": "🔁 Заповнити знову",
"rules_home": "🏠 Головна",
"rules_additional": " Додаткові",
"rules_next": "Далі ➡️",
"rules_prev": "⬅️ Назад"
"rules_prev": "⬅️ Назад",
"applying_stop": "🛑 Перервати заповнення"
},
"callback": {
"sub_accepted": "✅ Анкету {0} схвалено",
@ -133,7 +137,8 @@
"nothing": "🔔 Дія вже виконана",
"rules_page": " Показано правило {0}",
"rules_home": " Показано головну правил",
"rules_additional": " Показано додаткові правила"
"rules_additional": " Показано додаткові правила",
"reapply_stopped": " Перервано заповнення анкети"
},
"inline": {
"forbidden": {

69
main.py
View File

@ -243,22 +243,51 @@ async def cmd_reapply(app, msg):
if configGet("approved", file=str(msg.from_user.id)) or configGet("refused", file=str(msg.from_user.id)):
if (configGet("stage", file=str(msg.from_user.id)) == 10) and not (configGet("sent", file=str(msg.from_user.id))):
configSet(["reapply"], True, file=str(msg.from_user.id))
configSet(["confirmed"], False, file=str(msg.from_user.id))
await welcome_pass(app, msg, once_again=True)
left_chat = True
async for member in app.get_chat_members(configGet("destination_group")):
if member.user.id == msg.from_user.id:
left_chat = False
if not left_chat:
configSet(["reapply"], True, file=str(msg.from_user.id))
configSet(["confirmed"], False, file=str(msg.from_user.id))
await welcome_pass(app, msg, once_again=True)
else:
await msg.reply_text(locale("reapply_left_chat", "message"), reply_markup=InlineKeyboardMarkup([
[
InlineKeyboardButton(locale("reapply_old_one", "button"), f"reapply_old_{msg.from_user.id}")
],
[
InlineKeyboardButton(locale("reapply_new_one", "button"), f"reapply_new_{msg.from_user.id}")
]
]))
else:
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0])) # type: ignore
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0]), reply_markup=InlineKeyboardMarkup([
[
InlineKeyboardButton(locale("applying_stop", "button"), f"reapply_stop_{msg.id}")
]
])) # type: ignore
else:
if configGet("sent", file=str(msg.from_user.id)):
await msg.reply_text(locale("reapply_forbidden", "message"))
else:
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0])) # type: ignore
await msg.reply_text(locale("reapply_in_progress", "message").format(locale("confirm", "keyboard")[1][0]), reply_markup=InlineKeyboardMarkup([
[
InlineKeyboardButton(locale("applying_stop", "button"), f"reapply_stop_{msg.id}")
]
])) # type: ignore
# ==============================================================================================================================
# Welcome check ================================================================================================================
@app.on_message(~ filters.scheduled & filters.private & (filters.regex(locale("welcome", "keyboard")[0][0]) | filters.regex(locale("return", "keyboard")[0][0])))
async def welcome_pass(app, msg, once_again: bool = True):
async def welcome_pass(app, msg, once_again: bool = True) -> None:
"""Set user's stage to 1 and start a fresh application
### Args:
* app (app): Pyrogram Client to use
* msg (Message): Message with .from_user.id attribute equal to the end-user ID whose application will be started
* once_again (bool, optional): Set to False if it's the first time as user applies. Defaults to True.
"""
if not once_again:
await msg.reply_text(locale("privacy_notice", "message"))
@ -561,6 +590,34 @@ async def callback_query_reapply_refuse(app, clb):
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sub_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
# Use old application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_old_[\s\S]*")) # type: ignore
async def callback_query_reapply_old(app, clb):
pass
# Start a new application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_new_[\s\S]*")) # type: ignore
async def callback_query_reapply_new(app, clb):
pass
# Abort application fill in progress and restart it
@app.on_callback_query(filters.regex("reapply_stop_[\s\S]*")) # type: ignore
async def callback_query_reapply_stop(app, clb):
fullclb = clb.data.split("_")
user_stage = configGet("stage", file=str(clb.from_user.id))
jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}user_default.json"), f"{configGet('data', 'locations')}{sep}users{sep}{clb.from_user.id}.json")
configSet(["telegram_id"], str(clb.from_user.username), file=str(clb.from_user.id))
configSet(["telegram_name"], f"{clb.from_user.first_name} {clb.from_user.last_name}", file=str(clb.from_user.id))
configSet(["telegram_phone"], str(clb.from_user.phone_number), file=str(clb.from_user.id))
configSet(["telegram_locale"], str(clb.from_user.language_code), file=str(clb.from_user.id))
await clb.answer(locale("reapply_stopped", "callback"))
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
await welcome_pass(app, message, once_again=True)
logWrite(f"User {clb.from_user.id} restarted the application due to typo in it")
# ==============================================================================================================================