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/identify.py

106 lines
3.2 KiB
Python
Raw Permalink Normal View History

2023-01-03 15:30:16 +02:00
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
2023-01-06 16:49:51 +02:00
from classes.errors.holo_user import UserNotFoundError, UserInvalidError
from classes.holo_user import HoloUser
2023-03-09 17:25:06 +02:00
from modules.utils import (
jsonLoad,
should_quote,
logWrite,
locale,
download_tmp,
create_tmp,
find_user,
)
2023-01-03 15:30:16 +02:00
from modules import custom_filters
2023-03-09 17:25:06 +02:00
@app.on_message(
(custom_filters.enabled_applications | custom_filters.enabled_sponsorships)
& ~filters.scheduled
& filters.command("identify", prefixes=["/"])
& custom_filters.admin
)
2023-01-05 14:01:57 +02:00
async def cmd_identify(app: Client, msg: Message):
2023-01-03 15:30:16 +02:00
if len(msg.command) != 2:
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("identify_invalid_syntax", "message", locale=msg.from_user)
)
2023-01-03 15:30:16 +02:00
return
try:
try:
holo_user = HoloUser(int(msg.command[1]))
except ValueError:
2023-01-04 14:15:08 +02:00
holo_user = HoloUser(await find_user(app, msg.command[1]))
2023-03-09 17:25:06 +02:00
except (
UserInvalidError,
UserNotFoundError,
bad_request_400.UsernameInvalid,
bad_request_400.PeerIdInvalid,
bad_request_400.UsernameNotOccupied,
TypeError,
):
await msg.reply_text(
locale("identify_not_found", "message", locale=msg.from_user).format(
msg.command[1]
)
)
2023-01-03 15:30:16 +02:00
return
role = holo_user.label
2023-03-09 17:25:06 +02:00
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)
)
2023-01-03 15:30:16 +02:00
username = holo_user.username if holo_user.username is not None else "N/A"
2023-03-09 17:25:06 +02:00
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)
)
2023-01-03 15:30:16 +02:00
output = locale("identify_success", "message", locale=msg.from_user).format(
holo_user.id,
holo_user.name,
username,
in_chat,
is_admin,
role,
has_application,
2023-03-09 17:25:06 +02:00
has_sponsorship,
2023-01-03 15:30:16 +02:00
)
2023-03-09 17:25:06 +02:00
2023-01-03 15:30:16 +02:00
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(
2023-03-09 17:25:06 +02:00
create_tmp(
(await download_tmp(app, user.photo.big_file_id))[1], kind="image"
),
2023-01-03 15:30:16 +02:00
quote=should_quote(msg),
2023-03-09 17:25:06 +02:00
caption=output,
2023-01-03 15:30:16 +02:00
)
else:
await app.send_chat_action(msg.chat.id, action=ChatAction.TYPING)
2023-03-09 17:25:06 +02:00
await msg.reply_text(output, quote=should_quote(msg))
2023-01-03 15:30:16 +02:00
2023-01-05 14:01:57 +02:00
logWrite(f"User {msg.from_user.id} identified user {holo_user.id}")