This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/handlers/confirmation.py

95 lines
5.2 KiB
Python
Raw Normal View History

2022-12-05 19:49:51 +02:00
from dateutil.relativedelta import relativedelta
from datetime import datetime
from app import app
from pyrogram import filters
from pyrogram.types import ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.enums.parse_mode import ParseMode
2022-12-14 14:58:06 +02:00
from classes.holo_user import HoloUser
from modules.utils import configGet, locale, logWrite
2022-12-05 19:49:51 +02:00
from modules.handlers.welcome import welcome_pass
2022-12-14 14:58:06 +02:00
from modules.database import col_tmp
2022-12-05 19:49:51 +02:00
# Confirmation =================================================================================================================
@app.on_message(~ filters.scheduled & filters.private & (filters.regex(locale("confirm", "keyboard")[0][0])))
async def confirm_yes(app, msg):
2022-12-14 14:58:06 +02:00
holo_user = HoloUser(msg.from_user)
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
if (holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True):
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
await msg.reply_text(locale("application_sent", "message"), reply_markup=ReplyKeyboardRemove())
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
tmp_application = col_tmp.find_one({"user": holo_user.id, "type": "application"})
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
if tmp_application is None:
logWrite(f"Application of {holo_user.id} is nowhere to be found.")
return
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
application_content = []
i = 1
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
for question in tmp_application['application']:
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
if i == 2:
age = relativedelta(datetime.now(), tmp_application['application']['2'])
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
elif i == 3:
if tmp_application['application']['3']['countryCode'] == "UA":
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']}")
2022-12-05 19:49:51 +02:00
else:
2022-12-14 14:58:06 +02:00
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']} ({tmp_application['application']['3']['adminName1']}, {tmp_application['application']['3']['countryName']})")
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application'][question]}")
i += 1
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
if tmp_application["reapply"]:
await app.send_message(chat_id=configGet("admin_group"), text=(locale("reapply_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.last_name, msg.from_user.username, "\n".join(application_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
[
2022-12-05 19:49:51 +02:00
[
2022-12-14 14:58:06 +02:00
InlineKeyboardButton(text=str(locale("reapply_yes", "button")), callback_data=f"reapply_yes_{holo_user.id}")
],
[
InlineKeyboardButton(text=str(locale("reapply_no", "button")), callback_data=f"reapply_no_{holo_user.id}")
2022-12-05 19:49:51 +02:00
]
2022-12-14 14:58:06 +02:00
]
2022-12-15 15:31:57 +02:00
),
parse_mode=ParseMode.MARKDOWN
2022-12-14 14:58:06 +02:00
)
else:
await app.send_message(chat_id=configGet("admin_group"), text=(locale("application_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.last_name, msg.from_user.username, "\n".join(application_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
[
2022-12-05 19:49:51 +02:00
[
2022-12-14 14:58:06 +02:00
InlineKeyboardButton(text=str(locale("sub_yes", "button")), callback_data=f"sub_yes_{holo_user.id}")
],
[
InlineKeyboardButton(text=str(locale("sub_no", "button")), callback_data=f"sub_no_{holo_user.id}")
],
[
2022-12-15 14:50:11 +02:00
InlineKeyboardButton(text=str(locale("sub_aggressive", "button")), callback_data=f"sub_aggressive_{holo_user.id}")
2022-12-14 14:58:06 +02:00
],
[
2022-12-15 14:50:11 +02:00
InlineKeyboardButton(text=str(locale("sub_russian", "button")), callback_data=f"sub_russian_{holo_user.id}")
2022-12-05 19:49:51 +02:00
]
2022-12-14 14:58:06 +02:00
]
2022-12-15 15:31:57 +02:00
),
parse_mode=ParseMode.MARKDOWN
2022-12-14 14:58:06 +02:00
)
logWrite(f"User {holo_user.id} sent his application and it will now be reviewed")
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
col_tmp.update_one({"user": holo_user.id, "type": "application"}, {"$set": {"sent": True}})
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
# configSet(["sent"], True, file=str(holo_user.id))
# configSet(["confirmed"], True, file=str(holo_user.id))
2022-12-05 19:49:51 +02:00
@app.on_message(~ filters.scheduled & filters.private & (filters.regex(locale("confirm", "keyboard")[1][0])))
async def confirm_no(app, msg):
2022-12-14 14:58:06 +02:00
holo_user = HoloUser(msg.from_user)
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
if (holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True):
holo_user.application_restart()
2022-12-05 19:49:51 +02:00
await welcome_pass(app, msg, once_again=True)
logWrite(f"User {msg.from_user.id} restarted the application due to typo in it")
# ==============================================================================================================================