2022-12-05 19:49:51 +02:00
|
|
|
|
from os import sep, path
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from app import app, isAnAdmin
|
|
|
|
|
from pyrogram import filters
|
|
|
|
|
from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
|
|
|
|
from modules.utils import configGet, jsonLoad, logWrite, locale, should_quote
|
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
|
|
# Applications command =========================================================================================================
|
|
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["application"], prefixes=["/"]))
|
|
|
|
|
async def cmd_application(app, msg):
|
|
|
|
|
|
|
|
|
|
if (await isAnAdmin(msg.from_user.id)) or (msg.chat.id == configGet("admin_group")):
|
|
|
|
|
try:
|
|
|
|
|
if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json")["approved"]):
|
|
|
|
|
user_id = int(msg.command[1])
|
|
|
|
|
else:
|
|
|
|
|
list_of_users = []
|
|
|
|
|
async for m in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
|
|
|
|
list_of_users.append(m)
|
|
|
|
|
user_id = list_of_users[0].user.id
|
|
|
|
|
try:
|
|
|
|
|
user_data = jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{user_id}.json")
|
|
|
|
|
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")[str(user_id)]
|
|
|
|
|
application_content = []
|
|
|
|
|
i = 1
|
|
|
|
|
for question in configGet("application", file=str(msg.from_user.id)):
|
|
|
|
|
if i == 2:
|
|
|
|
|
age = relativedelta(datetime.now(), datetime.strptime(application['application']['2'], '%d.%m.%Y'))
|
|
|
|
|
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {application['application']['2']} ({age.years} р.)")
|
|
|
|
|
else:
|
|
|
|
|
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {application['application'][question]}")
|
|
|
|
|
i += 1
|
|
|
|
|
if user_data["sent"]:
|
|
|
|
|
if user_data["approved"]:
|
2022-12-06 11:26:22 +02:00
|
|
|
|
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["approved_by"])).first_name, datetime.fromtimestamp(application["approval_date"]).strftime("%d.%m.%Y, %H:%M"))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
elif application["refused"]:
|
2022-12-06 11:26:22 +02:00
|
|
|
|
application_status = locale("application_status_refused", "message").format((await app.get_users(application["refused_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
else:
|
|
|
|
|
application_status = locale("application_status_on_hold", "message")
|
|
|
|
|
else:
|
|
|
|
|
if user_data["approved"]:
|
2022-12-06 11:26:22 +02:00
|
|
|
|
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["approved_by"])).first_name, datetime.fromtimestamp(application["approval_date"]).strftime("%d.%m.%Y, %H:%M"))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
elif application["refused"]:
|
2022-12-06 11:26:22 +02:00
|
|
|
|
application_status = locale("application_status_refused", "message").format((await app.get_users(application["refused_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
else:
|
|
|
|
|
application_status = locale("application_status_not_send", "message")
|
|
|
|
|
logWrite(f"User {msg.from_user.id} requested application of {user_id}")
|
2022-12-06 11:26:22 +02:00
|
|
|
|
await msg.reply_text(locale("contact", "message").format(str(user_id), "\n".join(application_content), application_status), quote=should_quote(msg))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
logWrite(f"User {msg.from_user.id} requested application of {user_id} but user does not exists")
|
|
|
|
|
await msg.reply_text(locale("contact_invalid", "message"), quote=should_quote(msg))
|
|
|
|
|
|
|
|
|
|
except IndexError:
|
|
|
|
|
await msg.reply_text(locale("application_invalid_syntax", "message"), quote=should_quote(msg))
|
|
|
|
|
# ==============================================================================================================================
|