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/commands/application.py

97 lines
6.5 KiB
Python
Raw Normal View History

2022-12-05 19:49:51 +02:00
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-15 15:32:17 +02:00
from pyrogram.enums.parse_mode import ParseMode
2022-12-27 14:36:54 +02:00
from pyrogram.types import Message
2022-12-15 15:32:17 +02:00
from pyrogram.errors import bad_request_400
2022-12-27 14:36:54 +02:00
from pyrogram.client import Client
2022-12-15 16:02:56 +02:00
from classes.holo_user import HoloUser, UserNotFoundError
2022-12-15 15:52:33 +02:00
from modules.utils import logWrite, locale, should_quote
2022-12-05 19:49:51 +02:00
from dateutil.relativedelta import relativedelta
2022-12-15 15:32:17 +02:00
from modules.database import col_applications
2022-12-27 19:46:17 +02:00
from modules import custom_filters
2022-12-05 19:49:51 +02:00
# Applications command =========================================================================================================
2022-12-30 21:36:06 +02:00
@app.on_message(~ filters.scheduled & filters.command(["application"], prefixes=["/"]) & custom_filters.admin)
2022-12-27 14:36:54 +02:00
async def cmd_application(app: Client, msg: Message):
2022-12-05 19:49:51 +02:00
2022-12-27 19:46:17 +02:00
try:
2022-12-15 15:32:17 +02:00
2022-12-05 19:49:51 +02:00
try:
2022-12-27 19:46:17 +02:00
holo_user = HoloUser(int(msg.command[1]))
except (ValueError, UserNotFoundError):
2022-12-05 19:49:51 +02:00
try:
2022-12-27 19:46:17 +02:00
holo_user = HoloUser((await app.get_users(msg.command[1])).id)
except (bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid):
await msg.reply_text(locale("no_user_application", "message", locale=msg.from_user).format(msg.command[1]), quote=should_quote(msg))
return
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
application = col_applications.find_one({"user": holo_user.id})
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
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
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
application_content = []
i = 1
2022-12-16 12:27:46 +02:00
2022-12-27 19:46:17 +02:00
for question in application['application']:
2022-12-15 15:32:17 +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=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']}")
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=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
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
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"))
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
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))
2022-12-15 15:32:17 +02:00
2022-12-27 19:46:17 +02:00
# 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"]:
# 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"))
# elif application["rejected"]:
# application_status = locale("application_status_rejected", "message").format((await app.get_users(application["rejected_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
# else:
# application_status = locale("application_status_on_hold", "message")
# else:
# if user_data["approved"]:
# 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"))
# elif application["rejected"]:
# application_status = locale("application_status_rejected", "message").format((await app.get_users(application["rejected_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
# else:
# application_status = locale("application_status_not_send", "message")
# logWrite(f"User {msg.from_user.id} requested application of {user_id}")
# await msg.reply_text(locale("contact", "message").format(str(user_id), "\n".join(application_content), application_status), quote=should_quote(msg))
except IndexError:
await msg.reply_text(locale("application_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
2022-12-05 19:49:51 +02:00
# ==============================================================================================================================