2022-05-23 12:40:30 +00:00
|
|
|
from os import remove
|
|
|
|
|
|
|
|
from pyrogram.errors import UsernameNotOccupied, PeerIdInvalid
|
|
|
|
from pyrogram.types import User
|
|
|
|
|
|
|
|
from pagermaid import Config
|
|
|
|
from pagermaid.listener import listener
|
2022-09-01 08:35:19 +00:00
|
|
|
from pagermaid.enums import Message, Client
|
|
|
|
from pagermaid.utils import lang
|
2022-05-23 12:40:30 +00:00
|
|
|
|
2022-06-20 13:55:14 +00:00
|
|
|
import contextlib
|
2022-05-23 12:40:30 +00:00
|
|
|
|
2022-06-20 13:55:14 +00:00
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
command="profile",
|
|
|
|
description=lang("profile_des"),
|
|
|
|
parameters="<username>",
|
|
|
|
)
|
2022-09-01 08:35:19 +00:00
|
|
|
async def profile(client: Client, message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Queries profile of a user."""
|
2022-05-23 12:40:30 +00:00
|
|
|
if len(message.parameter) > 1:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
return
|
|
|
|
if not Config.SILENT:
|
2023-03-12 03:56:01 +00:00
|
|
|
message = await message.edit(lang("profile_process"))
|
2022-05-23 12:40:30 +00:00
|
|
|
if message.reply_to_message:
|
|
|
|
user = message.reply_to_message.from_user
|
|
|
|
if not user:
|
|
|
|
return await message.edit(f"{lang('error_prefix')}{lang('profile_e_no')}")
|
|
|
|
else:
|
|
|
|
if len(message.parameter) == 1:
|
|
|
|
user = message.parameter[0]
|
|
|
|
if user.isdigit():
|
|
|
|
user = int(user)
|
|
|
|
else:
|
2022-09-01 08:35:19 +00:00
|
|
|
user = await client.get_me()
|
2022-05-23 12:40:30 +00:00
|
|
|
if message.entities is not None:
|
|
|
|
if message.entities[0].type == "text_mention":
|
|
|
|
user = message.entities[0].user
|
|
|
|
elif message.entities[0].type == "phone_number":
|
|
|
|
user = int(message.parameter[0])
|
|
|
|
else:
|
|
|
|
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
if not isinstance(user, User):
|
|
|
|
try:
|
2022-09-01 08:35:19 +00:00
|
|
|
user = await client.get_users(user)
|
2022-05-23 12:40:30 +00:00
|
|
|
except PeerIdInvalid:
|
2023-03-12 03:56:01 +00:00
|
|
|
return await message.edit(
|
|
|
|
f"{lang('error_prefix')}{lang('profile_e_nof')}"
|
|
|
|
)
|
2022-05-23 12:40:30 +00:00
|
|
|
except UsernameNotOccupied:
|
2023-03-12 03:56:01 +00:00
|
|
|
return await message.edit(
|
|
|
|
f"{lang('error_prefix')}{lang('profile_e_nou')}"
|
|
|
|
)
|
2022-05-23 12:40:30 +00:00
|
|
|
except OverflowError:
|
2023-03-12 03:56:01 +00:00
|
|
|
return await message.edit(
|
|
|
|
f"{lang('error_prefix')}{lang('profile_e_long')}"
|
|
|
|
)
|
2022-05-23 12:40:30 +00:00
|
|
|
except Exception as exception:
|
|
|
|
raise exception
|
2023-03-12 03:56:01 +00:00
|
|
|
user_type = "Bot" if user.is_bot else lang("profile_user")
|
|
|
|
username_system = (
|
|
|
|
f"@{user.username}" if user.username is not None else lang("profile_noset")
|
|
|
|
)
|
2022-05-23 12:40:30 +00:00
|
|
|
if not user.first_name:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('profile_e_no')}")
|
|
|
|
return
|
|
|
|
first_name = user.first_name.replace("\u2060", "")
|
2023-03-12 03:56:01 +00:00
|
|
|
last_name = (
|
|
|
|
user.last_name.replace("\u2060", "")
|
|
|
|
if user.last_name is not None
|
|
|
|
else lang("profile_noset")
|
|
|
|
)
|
|
|
|
verified = lang("profile_yes") if user.is_verified else lang("profile_no")
|
|
|
|
restricted = lang("profile_yes") if user.is_restricted else lang("profile_no")
|
|
|
|
caption = (
|
|
|
|
f"**{lang('profile_name')}:** \n"
|
|
|
|
f"{lang('profile_username')}: {username_system} \n"
|
|
|
|
f"ID: {user.id} \n"
|
|
|
|
f"{lang('profile_fname')}: {first_name} \n"
|
|
|
|
f"{lang('profile_lname')}: {last_name} \n"
|
|
|
|
f"{lang('profile_verified')}: {verified} \n"
|
|
|
|
f"{lang('profile_restricted')}: {restricted} \n"
|
|
|
|
f"{lang('profile_type')}: {user_type} \n"
|
|
|
|
f"[{first_name}](tg://user?id={user.id})"
|
|
|
|
)
|
2024-02-04 07:33:01 +00:00
|
|
|
photo = await client.download_media(user.photo.big_file_id) if user.photo else None
|
2023-03-12 03:56:01 +00:00
|
|
|
reply_to = (
|
|
|
|
message.reply_to_message.id
|
|
|
|
if message.reply_to_message
|
2024-02-04 07:33:01 +00:00
|
|
|
else None
|
2023-03-12 03:56:01 +00:00
|
|
|
)
|
2024-02-04 07:33:01 +00:00
|
|
|
if photo:
|
|
|
|
try:
|
|
|
|
await client.send_photo(
|
|
|
|
message.chat.id, photo, caption=caption, reply_to_message_id=reply_to
|
|
|
|
)
|
|
|
|
await message.delete()
|
|
|
|
return remove(photo)
|
|
|
|
except TypeError:
|
|
|
|
await message.edit(caption)
|
|
|
|
else:
|
2022-05-23 12:40:30 +00:00
|
|
|
await message.edit(caption)
|
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="block",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("block_des"),
|
|
|
|
parameters="(username/uid/reply)",
|
|
|
|
)
|
2022-09-01 08:35:19 +00:00
|
|
|
async def block_user(client: Client, message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Block a user."""
|
2022-05-23 12:40:30 +00:00
|
|
|
if len(message.parameter) > 1:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
return
|
|
|
|
if not Config.SILENT:
|
2023-03-12 03:56:01 +00:00
|
|
|
message = await message.edit(lang("block_process"))
|
2022-05-25 11:26:50 +00:00
|
|
|
user = message.obtain_user()
|
2022-05-23 12:40:30 +00:00
|
|
|
if not user:
|
|
|
|
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2022-06-20 13:55:14 +00:00
|
|
|
with contextlib.suppress(Exception):
|
2022-09-01 08:35:19 +00:00
|
|
|
if await client.block_user(user):
|
2022-06-08 03:18:21 +00:00
|
|
|
return await message.edit(f"{lang('block_success')} `{user}`")
|
2022-05-23 12:40:30 +00:00
|
|
|
await message.edit(f"`{user}` {lang('block_exist')}")
|
|
|
|
|
|
|
|
|
2023-03-12 03:56:01 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=False,
|
|
|
|
outgoing=True,
|
|
|
|
command="unblock",
|
|
|
|
need_admin=True,
|
|
|
|
description=lang("unblock_des"),
|
|
|
|
parameters="<username/uid/reply>",
|
|
|
|
)
|
2022-09-01 08:35:19 +00:00
|
|
|
async def unblock_user(client: Client, message: Message):
|
2023-03-12 03:56:01 +00:00
|
|
|
"""Unblock a user."""
|
2022-05-23 12:40:30 +00:00
|
|
|
if len(message.parameter) > 1:
|
|
|
|
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
|
|
|
return
|
|
|
|
if not Config.SILENT:
|
2023-03-12 03:56:01 +00:00
|
|
|
message = await message.edit(lang("unblock_process"))
|
2022-05-25 11:26:50 +00:00
|
|
|
user = message.obtain_user()
|
2022-05-23 12:40:30 +00:00
|
|
|
if not user:
|
|
|
|
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
2022-06-20 13:55:14 +00:00
|
|
|
with contextlib.suppress(Exception):
|
2022-09-01 08:35:19 +00:00
|
|
|
if await client.unblock_user(user):
|
2022-06-08 03:18:21 +00:00
|
|
|
return await message.edit(f"{lang('unblock_success')} `{user}`")
|
2022-05-23 12:40:30 +00:00
|
|
|
await message.edit(f"`{user}` {lang('unblock_exist')}")
|