import html from pyrogram import Client, filters from pyrogram.errors.exceptions.bad_request_400 import MessageNotModified from .. import config, help_dict, get_entity, log_errors, public_log_errors ZWS = '\u200B' def _generate_sexy(entity, ping): text = getattr(entity, 'title', None) if not text: text = entity.first_name if entity.last_name: text += f' {entity.last_name}' sexy_text = html.escape(text or '') or '[DELETED]' if ping and entity.type in ('private', 'bot') and text: sexy_text = f'{sexy_text}' elif entity.username: sexy_text = f'{sexy_text}' elif not ping: sexy_text = sexy_text.replace('@', f'@{ZWS}') if entity.type == 'bot': sexy_text += ' [BOT]' if entity.is_verified: sexy_text += ' [VERIFIED]' if entity.is_support: sexy_text += ' [SUPPORT]' if entity.is_scam: sexy_text += ' [SCAM]' if getattr(entity, 'is_fake', None): sexy_text += ' [FAKE]' return sexy_text @Client.on_message(~filters.scheduled & ~filters.forwarded & ~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['info', 'whois'], prefixes=config['config']['prefixes'])) @log_errors @public_log_errors async def info(client, message): entity = message.chat.id command = message.command command.pop(0) if command: entity = ' '.join(command) elif not getattr(message.reply_to_message, 'empty', True): entity = message.reply_to_message.from_user or message.reply_to_message.chat try: entity, entity_client = await get_entity(client, entity) except BaseException as ex: await message.reply_text(f'{type(ex).__name__}: {str(ex)}', parse_mode=None) return text_ping = _generate_sexy(entity, True) text_unping = _generate_sexy(entity, False) text_ping += f'\nID: {entity.id}' text_unping += f'\nID: {entity.id}' if entity.dc_id: text_ping += f'\nDC ID: {entity.dc_id}' text_unping += f'\nDC ID: {entity.dc_id}' if entity.username: text_ping += f'\nUsername: @{entity.username}' text_unping += f'\nUsername: @{ZWS}{entity.username}' if entity.restrictions: restrictions = [] for r in entity.restrictions: restrictions.append(f"{r.reason}-{r.platform}") text_ping += f'\nRestrictions: {", ".join(restrictions)}' text_unping += f'\nRestrictions: {", ".join(restrictions)}' if entity.members_count: text_ping += f'\nMembers: {entity.members_count}' text_unping += f'\nMembers: {entity.members_count}' if entity.linked_chat: text_ping += f'\nLinked Chat: {_generate_sexy(entity.linked_chat, False)} [{entity.linked_chat.id}]' text_unping += f'\nLinked Chat: {_generate_sexy(entity.linked_chat, False)} [{entity.linked_chat.id}]' if entity.description or entity.bio: text_ping += f'\nDescription:\n{html.escape(entity.description or entity.bio)}' text_unping += f'\nDescription:\n{html.escape((entity.description or entity.bio).replace("@", "@" + ZWS))}' reply = await message.reply_text(text_unping, disable_web_page_preview=True) if text_ping != text_unping: try: await reply.edit_text(text_ping, disable_web_page_preview=True) except MessageNotModified: pass @Client.on_message(~filters.scheduled & ~filters.forwarded & ~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command('id', prefixes=config['config']['prefixes'])) @log_errors @public_log_errors async def id(client, message): text_unping = 'Chat ID:' if message.chat.username: text_unping = f'{text_unping}' text_unping += f' {message.chat.id}\n' text = 'Message ID:' if message.link: text = f'{text}' text += f' {message.message_id}\n' text_unping += text if message.from_user: text_unping += f'User ID: {message.from_user.id}\n' text_ping = text_unping reply = message.reply_to_message if not getattr(reply, 'empty', True): text_unping += '\n' text = 'Replied Message ID:' if reply.link: text = f'{text}' text += f' {reply.message_id}\n' text_unping += text text_ping = text_unping if reply.from_user: text = 'Replied User ID:' if reply.from_user.username: text = f'{text}' text += f' {reply.from_user.id}\n' text_unping += text text_ping += f'Replied User ID: {reply.from_user.id}\n' if reply.forward_from: text_unping += '\n' text = 'Forwarded User ID:' if reply.forward_from.username: text = f'{text}' text += f' {reply.forward_from.id}\n' text_unping += text text_ping += f'\nForwarded User ID: {reply.forward_from.id}\n' reply = await message.reply_text(text_unping, disable_web_page_preview=True) if text_unping != text_ping: await reply.edit_text(text_ping, disable_web_page_preview=True) help_dict['info'] = ('Info', '''{prefix}info <entity> - Get entity info {prefix}info (as reply to message) - Get entity info of replied user Aliases: {prefix}whois {prefix}id [maybe reply to message] - Gets IDs''')