Telegram/modules/handlers/confirmation.py

166 lines
8.9 KiB
Python
Raw Normal View History

2022-12-22 16:05:27 +02:00
from typing import Literal
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
2022-12-27 14:36:54 +02:00
from pyrogram.types import ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, Message
from pyrogram.client import Client
from pyrogram.enums.parse_mode import ParseMode
2022-12-14 14:58:06 +02:00
from classes.holo_user import HoloUser
2022-12-17 01:58:33 +02:00
from modules.utils import all_locales, configGet, locale, logWrite
2022-12-05 19:49:51 +02:00
from modules.handlers.welcome import welcome_pass
2023-01-11 13:28:58 +02:00
from modules.database import col_tmp, col_applications
2023-01-03 21:34:13 +02:00
from modules import custom_filters
2022-12-05 19:49:51 +02:00
# Confirmation =================================================================================================================
2022-12-17 01:58:33 +02:00
confirmation_1 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_1.append(pattern[0][0])
2023-01-30 12:28:23 +02:00
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]) & ~custom_filters.banned)
2023-01-03 21:34:13 +02:00
async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
holo_user = HoloUser(msg.from_user)
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
if configGet("enabled", "features", "applications") is True:
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
tmp_application = col_tmp.find_one({"user": holo_user.id, "type": "application"})
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
if tmp_application is None:
logWrite(f"Application of {holo_user.id} is nowhere to be found.")
return
if tmp_application["sent"] is True:
return
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
await msg.reply_text(locale("application_sent", "message"), reply_markup=ReplyKeyboardRemove())
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
application_content = []
i = 1
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
for question in tmp_application['application']:
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +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']}")
else:
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']})")
2022-12-05 19:49:51 +02:00
else:
2023-01-03 21:34:13 +02:00
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
2023-01-11 13:28:58 +02:00
if tmp_application["reapply"] is True and col_applications.find_one({"user": holo_user.id}) is not None:
await app.send_message(
chat_id=configGet("admin", "groups"),
text=(locale("reapply_got", "message")).format(str(holo_user.id),msg.from_user.first_name, msg.from_user.username, "\n".join(application_content)),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
2022-12-14 14:58:06 +02:00
[
2023-01-03 21:34:13 +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
]
2023-01-03 21:34:13 +02:00
)
2022-12-15 16:00:27 +02:00
)
2023-01-03 21:34:13 +02:00
else:
2023-01-11 13:28:58 +02:00
await app.send_message(
chat_id=configGet("admin", "groups"),
text=(locale("application_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(application_content)),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
2022-12-14 14:58:06 +02:00
[
2023-01-03 21:34:13 +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}")
],
[
InlineKeyboardButton(text=str(locale("sub_russian", "button")), callback_data=f"sub_russian_{holo_user.id}")
]
2022-12-05 19:49:51 +02:00
]
2023-01-03 21:34:13 +02:00
)
2022-12-15 16:00:27 +02:00
)
2022-12-14 14:58:06 +02:00
2023-01-03 21:34:13 +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
2023-01-03 21:34:13 +02:00
col_tmp.update_one({"user": holo_user.id, "type": "application"}, {"$set": {"sent": True}})
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
return
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
if configGet("enabled", "features", "sponsorships") is True:
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
tmp_sponsorship = col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"})
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
if tmp_sponsorship is None:
logWrite(f"Sponsorship of {holo_user.id} is nowhere to be found.")
return
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
if tmp_sponsorship["sent"] is True:
return
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
await msg.reply_text(locale("sponsorship_sent", "message"), reply_markup=ReplyKeyboardRemove())
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
sponsorship_content = []
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
for question in tmp_sponsorship['sponsorship']:
if question == "expires":
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question].strftime('%d.%m.%Y')}")
elif question == "proof":
continue
2023-01-03 21:34:13 +02:00
else:
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}")
2023-01-06 22:27:32 +02:00
await app.send_cached_media(configGet("admin", "groups"), tmp_sponsorship["sponsorship"]["proof"], caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
2022-12-22 16:05:27 +02:00
[
2023-01-03 21:34:13 +02:00
[
InlineKeyboardButton(text=str(locale("sponsor_yes", "button")), callback_data=f"sponsor_yes_{holo_user.id}")
],
[
InlineKeyboardButton(text=str(locale("sponsor_no", "button")), callback_data=f"sponsor_no_{holo_user.id}")
]
2022-12-22 16:05:27 +02:00
]
2023-01-03 21:34:13 +02:00
)
2022-12-22 16:05:27 +02:00
)
# remove(f"tmp{sep}{filename}.jpg")
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
logWrite(f"User {holo_user.id} sent his sponsorship application and it will now be reviewed")
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
col_tmp.update_one({"user": holo_user.id, "type": "sponsorship"}, {"$set": {"sent": True}})
2022-12-22 16:05:27 +02:00
2023-01-03 21:34:13 +02:00
return
2022-12-22 16:05:27 +02:00
2022-12-17 01:58:33 +02:00
confirmation_2 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_2.append(pattern[1][0])
2023-01-30 12:28:23 +02:00
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]) & ~custom_filters.banned)
2023-01-03 21:34:13 +02:00
async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
holo_user = HoloUser(msg.from_user)
2022-12-05 19:49:51 +02:00
2023-01-03 21:34:13 +02:00
if configGet("enabled", "features", "applications") is True:
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
holo_user.application_restart()
await welcome_pass(app, msg, once_again=True)
logWrite(f"User {msg.from_user.id} restarted the application due to typo in it")
return
if configGet("enabled", "features", "sponsorships") is True:
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
holo_user.sponsorship_restart()
await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale))))
logWrite(f"User {msg.from_user.id} restarted the sponsorship application due to typo in it")
return
2022-12-05 19:49:51 +02:00
# ==============================================================================================================================