2022-12-05 19:49:51 +02:00
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
from datetime import datetime
|
2022-12-27 19:46:17 +02:00
|
|
|
|
from app import app
|
2022-12-05 19:49:51 +02:00
|
|
|
|
from pyrogram import filters
|
2022-12-27 14:36:54 +02:00
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
from pyrogram.client import Client
|
2022-12-16 12:29:10 +02:00
|
|
|
|
from modules.utils import locale, logWrite
|
2022-12-16 12:27:32 +02:00
|
|
|
|
from modules.database import col_applications
|
|
|
|
|
from classes.holo_user import HoloUser
|
2022-12-27 19:46:17 +02:00
|
|
|
|
from modules import custom_filters
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
|
|
# Contact getting ==============================================================================================================
|
2023-01-03 21:34:13 +02:00
|
|
|
|
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin))
|
2022-12-27 14:36:54 +02:00
|
|
|
|
async def get_contact(app: Client, msg: Message):
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
|
|
|
|
holo_user = HoloUser(msg.from_user)
|
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
if msg.contact.user_id != None:
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
application = col_applications.find_one({"user": msg.contact.user_id})
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
if application is None:
|
|
|
|
|
logWrite(f"User {holo_user.id} requested application of {msg.contact.user_id} but user does not exists")
|
|
|
|
|
await msg.reply_text(locale("contact_invalid", "message", locale=holo_user.locale))
|
|
|
|
|
return
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
application_content = []
|
|
|
|
|
i = 1
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
for question in application['application']:
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
if i == 2:
|
|
|
|
|
age = relativedelta(datetime.now(), application['application']['2'])
|
|
|
|
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {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=holo_user.locale)} {application['application']['3']['name']}")
|
2022-12-05 19:49:51 +02:00
|
|
|
|
else:
|
2022-12-27 19:46:17 +02:00
|
|
|
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {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=holo_user.locale)} {application['application'][question]}")
|
|
|
|
|
|
|
|
|
|
i += 1
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
application_status = locale("application_status_accepted", "message", locale=holo_user.locale).format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
logWrite(f"User {holo_user.id} requested application of {msg.contact.user_id}")
|
|
|
|
|
await msg.reply_text(locale("contact", "message", locale=holo_user.locale).format(str(msg.contact.user_id), "\n".join(application_content), application_status))
|
|
|
|
|
|
2022-12-16 12:27:32 +02:00
|
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
|
else:
|
|
|
|
|
logWrite(f"User {holo_user.id} requested application of someone but user is not telegram user")
|
|
|
|
|
await msg.reply_text(locale("contact_not_member", "message", locale=holo_user.locale))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
# ==============================================================================================================================
|