from datetime import datetime from app import app from pyrogram import filters from pyrogram.enums.parse_mode import ParseMode from pyrogram.types import Message from pyrogram.errors import bad_request_400 from pyrogram.client import Client from classes.errors.holo_user import UserNotFoundError from classes.holo_user import HoloUser from modules.utils import logWrite, locale, should_quote from dateutil.relativedelta import relativedelta from modules.database import col_applications from modules import custom_filters @app.on_message( custom_filters.enabled_applications & ~filters.scheduled & filters.command(["application"], prefixes=["/"]) & custom_filters.admin ) async def cmd_application(app: Client, msg: Message): try: try: holo_user = HoloUser(int(msg.command[1])) except (ValueError, UserNotFoundError): try: holo_user = HoloUser((await app.get_users(msg.command[1])).id) except ( bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid, bad_request_400.UsernameNotOccupied, ): await msg.reply_text( locale( "no_user_application", "message", locale=msg.from_user ).format(msg.command[1]), quote=should_quote(msg), ) return application = col_applications.find_one({"user": holo_user.id}) if application is None: logWrite( f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists" ) await msg.reply_text( locale("user_invalid", "message", locale=msg.from_user), quote=should_quote(msg), ) return application_content = [] i = 1 for question in application["application"]: if i == 2: age = relativedelta(datetime.now(), application["application"]["2"]) application_content.append( f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)" ) elif i == 3: if application["application"]["3"]["countryCode"] == "UA": application_content.append( f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']}" ) else: application_content.append( f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})" ) else: application_content.append( f"{locale(f'question{i}', 'message', 'question_titles', locale=msg.from_user)} {application['application'][question]}" ) i += 1 application_status = locale( "application_status_accepted", "message", locale=msg.from_user ).format( (await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"), ) logWrite(f"User {msg.from_user.id} requested application of {holo_user.id}") await msg.reply_text( locale("contact", "message", locale=msg.from_user).format( holo_user.id, "\n".join(application_content), application_status ), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg), ) except IndexError: await msg.reply_text( locale("application_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg), )