diff --git a/holochecker.py b/holochecker.py index bb70530..c2ad999 100644 --- a/holochecker.py +++ b/holochecker.py @@ -13,6 +13,7 @@ makedirs(f'{configGet("cache", "locations")}{sep}avatars', exist_ok=True) from modules.commands.application import * from modules.commands.applications import * from modules.commands.cancel import * +from modules.commands.identify import * from modules.commands.label import * from modules.commands.message import * from modules.commands.nearby import * diff --git a/locale/uk.json b/locale/uk.json index d8dc1ba..2ead0de 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -97,7 +97,11 @@ "nearby_result": "Результати пошуку:\n\n{0}", "nearby_empty": "Здається, нікого поблизу немає.", "cancel": "Всі поточні операції скасовано.", + "identify_invalid_syntax": "Неправильний синтаксис!\nТреба: `/identify ID/NAME/USERNAME`", + "identify_not_found": "Не знайдено користувачів за запитом **{0}**", "identify_success": "Користувач `{0}`\n\nІм'я: {1}\nЮзернейм: {2}\nЄ в чаті: {3}\nЄ адміном: {4}\nРоль: {5}\nНаявна анкета: {6}\nНаявне спонсорство: {7}", + "yes": "Так", + "no": "Ні", "voice_message": [ "why are u gae", "руки відірвало? пиши як людина", diff --git a/modules/commands/identify.py b/modules/commands/identify.py new file mode 100644 index 0000000..ad696c4 --- /dev/null +++ b/modules/commands/identify.py @@ -0,0 +1,63 @@ +from os import path +from app import app, isAnAdmin +from pyrogram import filters +from pyrogram.types import Message +from pyrogram.client import Client +from pyrogram.errors import bad_request_400 +from pyrogram.enums.chat_action import ChatAction +from classes.holo_user import HoloUser, UserNotFoundError, UserInvalidError +from modules.utils import jsonLoad, should_quote, logWrite, locale, download_tmp, create_tmp +from modules import custom_filters + +@app.on_message(~ filters.scheduled & filters.command("identify", prefixes=["/"]) & custom_filters.admin) +async def command_identify(app: Client, msg: Message): + + if len(msg.command) != 2: + await msg.reply_text(locale("identify_invalid_syntax", "message", locale=msg.from_user)) + return + + try: + try: + holo_user = HoloUser(int(msg.command[1])) + except ValueError: + holo_user = HoloUser(await app.get_users(msg.command[1])) + except (UserInvalidError, UserNotFoundError, bad_request_400.UsernameInvalid, bad_request_400.PeerIdInvalid, bad_request_400.UsernameNotOccupied): + await msg.reply_text(locale("identify_not_found", "message", locale=msg.from_user).format(msg.command[1])) + return + + role = holo_user.label + has_application = locale("yes", "message", locale=msg.from_user) if holo_user.application_approved() is True else locale("no", "message", locale=msg.from_user) + has_sponsorship = locale("yes", "message", locale=msg.from_user) if holo_user.sponsorship_valid() is True else locale("no", "message", locale=msg.from_user) + + username = holo_user.username if holo_user.username is not None else "N/A" + in_chat = locale("yes", "message", locale=msg.from_user) if (holo_user.id in jsonLoad(path.join("cache", "group_members"))) else locale("no", "message", locale=msg.from_user) + is_admin = locale("yes", "message", locale=msg.from_user) if (await isAnAdmin(holo_user.id)) else locale("no", "message", locale=msg.from_user) + + output = locale("identify_success", "message", locale=msg.from_user).format( + holo_user.id, + holo_user.name, + username, + in_chat, + is_admin, + role, + has_application, + has_sponsorship + ) + + user = await app.get_users(holo_user.id) + + if user.photo is not None: + await app.send_chat_action(msg.chat.id, action=ChatAction.UPLOAD_PHOTO) + await msg.reply_photo( + create_tmp(await download_tmp(app, user.photo.big_file_id), kind="image"), + quote=should_quote(msg), + caption=output + ) + else: + await app.send_chat_action(msg.chat.id, action=ChatAction.TYPING) + await msg.reply_text( + output, + quote=should_quote(msg) + ) + + logWrite(f"User {msg.from_user.id} identified user {holo_user.id}") \ No newline at end of file diff --git a/modules/utils.py b/modules/utils.py index c90d473..880d087 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -192,7 +192,7 @@ def find_location(query: str) -> dict: except (ValueError, KeyError, IndexError): raise PlaceNotFoundError(query) -def create_tmp(bytedata: Union[bytes, bytearray], kind: Union[Literal["image", "video"], None]) -> str: +def create_tmp(bytedata: Union[bytes, bytearray], kind: Union[Literal["image", "video"], None] = None) -> str: """Create temporary file to help uploading it ### Args: