File size: 3,729 Bytes
1cbc430
facee4e
8e64093
aacfc28
1cbc430
8e64093
facee4e
1cbc430
 
8e64093
 
5896d7f
1cbc430
5896d7f
1cbc430
 
 
 
 
5896d7f
1cbc430
 
5896d7f
 
1cbc430
 
 
 
5896d7f
1cbc430
 
5896d7f
1cbc430
8e64093
 
5896d7f
1cbc430
5896d7f
1cbc430
 
 
 
 
 
 
 
5896d7f
1cbc430
 
 
 
 
 
 
5896d7f
1cbc430
 
 
 
 
 
5896d7f
1cbc430
8e64093
 
5896d7f
1cbc430
 
aaf56af
1cbc430
aaf56af
1cbc430
aaf56af
1cbc430
5896d7f
1cbc430
 
5896d7f
1cbc430
8e64093
 
 
facee4e
5896d7f
8e64093
facee4e
8e64093
 
 
 
5896d7f
8e64093
 
 
 
facee4e
1cbc430
 
 
aaf56af
1cbc430
aaf56af
1cbc430
5896d7f
1cbc430
5896d7f
1cbc430
facee4e
8e64093
5896d7f
facee4e
8e64093
1cbc430
 
 
 
5896d7f
 
1cbc430
fec5a2d
1cbc430
 
8e64093
4ce98fd
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
from traceback import format_exc

from pyrogram import filters
from pyrogram.types import Message

from Powers import DEV_USERS, SUDO_USERS, WHITELIST_USERS, SUPPORT_STAFF, LOGGER
from Powers.bot_class import Gojo
from Powers.utils.custom_filters import command


async def get_user_info(user, already=False):
    if not already:
        user = await app.get_users(user)
    if not user.first_name:
        return ["Deleted account", None]
    user_id = user.id
    username = user.username
    first_name = user.first_name
    mention = user.mention("Link")
    dc_id = user.dc_id
    photo_id = user.photo.big_file_id if user.photo else None

    karma = await user_global_karma(user_id)
    body = {
        "ID": user_id,
        "DC": dc_id,
        "Name": [first_name],
        "Username": [("@" + username) if username else "Null"],
        "Mention": [mention],
    }
    caption = section("User info", body)
    return [caption, photo_id]


async def get_chat_info(chat, already=False):
    if not already:
        chat = await app.get_chat(chat)
    chat_id = chat.id
    username = chat.username
    title = chat.title
    type_ = chat.type
    is_scam = chat.is_scam
    description = chat.description
    members = chat.members_count
    is_restricted = chat.is_restricted
    link = f"[Link](t.me/{username})" if username else "Null"
    dc_id = chat.dc_id
    photo_id = chat.photo.big_file_id if chat.photo else None
    body = {
        "ID": chat_id,
        "DC": dc_id,
        "Type": type_,
        "Name": [title],
        "Username": [("@" + username) if username else "Null"],
        "Mention": [link],
        "Members": members,
        "Scam": is_scam,
        "Restricted": is_restricted,
        "Description": [description],
    }
    caption = section("Chat info", body)
    return [caption, photo_id]


@app.on_message(command("info") & ~filters.edited)
async def info_func(_, message: Message):
    if message.reply_to_message:
        user = message.reply_to_message.from_user.id
    elif not message.reply_to_message and len(message.command) == 1:
        user = message.from_user.id
    elif not message.reply_to_message and len(message.command) != 1:
        user = message.text.split(None, 1)[1]

    m = await message.reply_text("Processing")

    try:
        info_caption, photo_id = await get_user_info(user)
    except Exception as e:
        return await m.edit(str(e))

    if not photo_id:
        return await m.edit(info_caption, disable_web_page_preview=True)
    photo = await app.download_media(photo_id)

    await message.reply_photo(photo, caption=info_caption, quote=False)
    await m.delete()
    os.remove(photo)


@app.on_message(command("chat_info") & ~filters.edited)
async def chat_info_func(_, message: Message):
    try:
        if len(message.command) > 2:
            return await message.reply_text(
                "**Usage:**/chat_info [USERNAME|ID]"
            )

        if len(message.command) == 1:
            chat = message.chat.id
        elif len(message.command) == 2:
            chat = message.text.split(None, 1)[1]

        m = await message.reply_text("Processing")

        info_caption, photo_id = await get_chat_info(chat)
        if not photo_id:
            return await m.edit(info_caption, disable_web_page_preview=True)

        photo = await app.download_media(photo_id)
        await message.reply_photo(photo, caption=info_caption, quote=False)

        await m.delete()
        os.remove(photo)
    except Exception as e:
        await m.edit(e)
        
        
__PLUGIN__ = "info"
__alt_name__ = [
    "info",
    "chinfo",
] 

__HELP__ = """/info - To get info about the user
/chinfo - To get info about the chat"""