File size: 9,643 Bytes
9db4ada
0e31799
9db4ada
f0f9ad9
bfc34a2
f0f9ad9
9db4ada
f0f9ad9
c1d601a
f0f9ad9
0d887f0
3925c05
f0f9ad9
 
6e5ac37
 
 
af1662b
 
42a7e92
 
b51521e
ef4e395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0364f1a
 
 
ef4e395
 
 
 
 
 
 
 
 
 
 
 
0364f1a
 
 
14c8b0e
6e5ac37
af1662b
0364f1a
fa6f4d3
0d887f0
87696ba
0d887f0
 
af1662b
d5348c6
fa6f4d3
af1662b
769060e
fa6f4d3
af1662b
fa6f4d3
 
0d887f0
 
 
18c86d3
fac74eb
0d887f0
18c86d3
 
0d887f0
0249134
26ed39a
 
de34607
fac74eb
c68d102
fac74eb
c68d102
fac74eb
c68d102
de34607
 
3b5a27c
 
3e4ad47
fac74eb
 
 
af1662b
3fb2204
 
 
aa45406
3fb2204
aa45406
3fb2204
aa45406
3fb2204
aa45406
3fb2204
aa45406
3fb2204
 
49a551d
af1662b
fac74eb
 
af1662b
18c86d3
0e31799
18c86d3
0e31799
18c86d3
26ed39a
0e31799
26ed39a
18c86d3
26ed39a
 
18c86d3
26ed39a
18c86d3
26ed39a
18c86d3
26ed39a
18c86d3
 
 
 
af1662b
18c86d3
42a7e92
 
fa6f4d3
0d887f0
769060e
0d887f0
 
7eb17b1
0d887f0
26ed39a
0d887f0
fac74eb
0d887f0
 
 
 
 
fac74eb
c1d601a
3a7618b
18c86d3
 
 
 
 
26ed39a
18c86d3
2cf0846
aa46d17
 
b51521e
aa46d17
26ed39a
 
 
ef4e395
18c86d3
b2229d5
5ea462e
18c86d3
 
 
 
42a7e92
 
af1662b
3925c05
769060e
d5348c6
769060e
af1662b
 
 
 
3925c05
d5348c6
af1662b
1c31c3e
6fefa14
 
e44597a
14c8b0e
6fefa14
 
 
 
 
 
0e31799
7eb17b1
0e31799
 
6fefa14
 
7eb17b1
6e5ac37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fefa14
 
6e5ac37
6fefa14
14c8b0e
af1662b
fa6f4d3
af1662b
6e5ac37
 
725787c
6e5ac37
 
af1662b
6e5ac37
 
 
 
 
 
 
 
 
0d887f0
6e5ac37
d8d7492
6e5ac37
7ac55fa
5942ba9
 
 
 
 
 
6e5ac37
0e31799
7eb17b1
6e5ac37
42a7e92
6e5ac37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d887f0
c224902
fac74eb
 
 
6e5ac37
 
 
 
af1662b
0d887f0
a06c0e6
0d887f0
 
af1662b
8a5a595
709df35
096ee5f
709df35
d5348c6
 
423e59b
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import os
from asyncio import sleep
from pyrogram import enums
from datetime import datetime
from Powers.vars import Config
from traceback import format_exc
from Powers.bot_class import Gojo
from pyrogram.types import Message
from pyrogram.enums import ChatType
from Powers.database.antispam_db import GBan
from Powers.utils.custom_filters import command
from Powers.utils.extract_user import extract_user
from Powers import (
    LOGGER, DEV_USERS, SUDO_USERS, SUPPORT_STAFF, WHITELIST_USERS)
from pyrogram.errors import (
    RPCError, MessageTooLong, EntityBoundsInvalid, MediaCaptionTooLong)


gban_db = GBan()


async def count(c: Gojo, chat):
    try:
        administrator = []
        async for admin in c.get_chat_members(
            chat_id=chat, filter=enums.ChatMembersFilter.ADMINISTRATORS
        ):
            administrator.append(admin)
        total_admin = administrator
        bot = []
        async for tbot in c.get_chat_members(
            chat_id=chat, filter=enums.ChatMembersFilter.BOTS
        ):
            bot.append(tbot)

        total_bot = bot
        bot_admin = 0
        ban = []
        async for banned in c.get_chat_members(
            chat, filter=enums.ChatMembersFilter.BANNED
        ):
            ban.append(banned)

        total_banned = ban
        for x in total_admin:
            for y in total_bot:
                if x == y:
                    bot_admin += 1
        total_admin = len(total_admin)
        total_bot = len(total_bot)
        total_banned = len(total_banned)
        return total_bot, total_admin, bot_admin, total_banned
    except Exception as e:
        total_bot = (
            total_admin
        ) = bot_admin = total_banned = "Can't fetch due to some error."

    return total_bot, total_admin, bot_admin, total_banned


async def user_info(c: Gojo, user, already=False):
    if not already:
        user = await c.get_users(user_ids=user)
    if not user.first_name:
        return ["Deleted account", None]

    gbanned, reason_gban = gban_db.get_gban(user.id)
    if gbanned:
        gban = True
        reason = f"The user is gbanned because {reason_gban}"
    else:
        gban = False
        reason = "User is not gbanned"

    user_id = user.id
    username = user.username
    first_name = user.first_name
    last_name = user.last_name
    mention = user.mention(f"{first_name}")
    dc_id = user.dc_id
    is_verified = user.is_verified
    is_restricted = user.is_restricted
    photo_id = user.photo.big_file_id if user.photo else None
    is_support = True if user_id in SUPPORT_STAFF else False
    if user_id == Config.BOT_ID:
        is_support = "A person is a great support to himself"
    if is_support or Config.BOT_ID:
        if user_id in DEV_USERS:
            omp = "User is dev"
        elif user_id in SUDO_USERS:
            omp = "User is sudoer"
        elif user_id in WHITELIST_USERS:
            omp = "User is in whitelist"
        elif user_id == Config.BOT_ID:
            omp = "I am the targeted user"
    else:
        omp = "Hmmm.......Who is that again?"

    is_bot = user.is_bot
    is_fake = user.is_fake
    status = user.status

    if is_bot is True:
        last_date = "Targeted user is a bot"
    elif status == "recently":
        last_date = "Last seen Recently"
    elif status == "within_week":
        last_date = "Last seen within the last week"
    elif status == "within_month":
        last_date = "Last seen within the last month"
    elif status == "long_time_ago":
        last_date = "Last seen a long time ago or may be I am blocked by the user  :("
    elif status == "online":
        last_date = "User is currently Online"
    elif status == "offline":
        last_date = datetime.fromtimestamp(user.status.date).strftime(
            "%Y-%m-%d %H:%M:%S"
        )
    else:
        last_date = "User is currently online"

    caption = f"""
<b><i><u>⚑️ Extracted User info From Telegram ⚑️</b></i></u>

<b>πŸ†” User ID</b>: <code>{user_id}</code>
<b>πŸ“Ž Link To Profile</b>: <a href='tg://user?id={user_id}'>Click HereπŸšͺ</a>
<b>🫡 Mention</b>: {mention}
<b>πŸ—£ First Name</b>: <code>{first_name}</code>
<b>πŸ”… Second Name</b>: <code>{last_name}</code>
<b>πŸ” Username</b>: {("@" + username) if username else "NA"}
<b>πŸ§‘β€πŸ’» Support</b>: {is_support}
<b>πŸ₯· Support user type</b>: <code>{omp}</code>
<b>πŸ’£ Gbanned</b>: {gban}
<b>☠️ Gban reason</b>: <code>{reason}</code>
<b>🌐 DC ID</b>: {dc_id}
<b>βœ‹ RESTRICTED</b>: {is_restricted}
<b>βœ… VERIFIED</b>: {is_verified}
<b>❌ FAKE</b> : {is_fake}
<b>πŸ€– BOT</b>: {is_bot}
<b>πŸ‘€ Last seen</b>: <code>{last_date}</code>

"""

    return caption, photo_id


async def chat_info(c: Gojo, chat, already=False):
    if not already:
        chat = await c.get_chat(chat)
    chat_id = chat.id
    username = chat.username
    total_bot, total_admin, total_bot_admin, total_banned = await count(c, chat.id)
    title = chat.title
    type_ = str(chat.type).split(".")[1]
    is_scam = chat.is_scam
    is_fake = chat.is_fake
    description = chat.description
    members = chat.members_count
    is_restricted = chat.is_restricted
    dc_id = chat.dc_id
    photo_id = chat.photo.big_file_id if chat.photo else None
    can_save = chat.has_protected_content
    linked_chat = chat.linked_chat

    caption = f"""
πŸ”° <b>CHAT INFO</b> πŸ”°

<b>πŸ†” ID</b>: <code>{chat_id}</code>
<b>πŸš€ Chat Title</b>: {title}
<b>✨ Chat Type</b>: {type_}
<b>🌐 DataCentre ID</b>: {dc_id}
<b>πŸ” Username</b>: {("@" + username) if username else "NA"}
<b>⚜️ Administrators</b>: {total_admin}
<b>πŸ€– Bots</b>: {total_bot}
<b>🚫 Banned</b>: {total_banned}
<b>⚜️ Admin πŸ€– Bots</b>: {total_bot_admin}
<b>⁉️ Scam</b>: {is_scam}
<b>❌ Fake</b>: {is_fake}
<b>βœ‹ Restricted</b>: {is_restricted}
<b>πŸ‘¨πŸΏβ€πŸ’» Description</b>: <code>{description}</code>
<b>πŸ‘ͺ Total members</b>: {members}
<b>🚫 Has Protected Content</b>: {can_save}
<b>πŸ”— Linked Chat</b>: <code>{linked_chat.id if linked_chat else "Not Linked"}</code>

"""

    return caption, photo_id


@Gojo.on_message(command(["info", "whois"]))
async def info_func(c: Gojo, message: Message):
    try:
        user, _, user_name = await extract_user(c, message)
    except Exception as e:
        return await message.reply_text(
            f"Got an error while running extract_user function error is {e}.....Give this message in supoort group"
        )

    if not user:
        await message.reply_text("Can't find user to fetch info!")

    m = await message.reply_text(f"Fetching user info from telegram's database...")

    try:
        info_caption, photo_id = await user_info(c, user)

    except Exception as e:
        LOGGER.error(e)
        LOGGER.error(format_exc())
        return await m.edit(str(e))

    if not photo_id:
        await m.delete()
        await sleep(2)
        return await message.reply_text(info_caption, disable_web_page_preview=True)
    photo = await c.download_media(photo_id)

    await m.delete()
    await sleep(2)
    try:
        await message.reply_photo(photo, caption=info_caption, quote=False)
    except MediaCaptionTooLong:
        x = await message.reply_photo(photo)
        try:
            await x.reply_text(info_caption)
        except EntityBoundsInvalid:
            await x.delete()
            await message.reply_text(info_caption)
        except RPCError as rpc:
            await message.reply_text(rpc)
            LOGGER.error(rpc)
            LOGGER.error(format_exc())
    except Exception as e:
        await message.reply_text(text=e)
        LOGGER.error(e)
        LOGGER.error(format_exc())

    os.remove(photo)

    return


@Gojo.on_message(command(["chinfo", "chatinfo", "chat_info"]))
async def chat_info_func(c: Gojo, message: Message):
    splited = message.text.split()
    if len(splited) == 1:
        chat = message.chat.id

    else:
        chat = splited[1]

    try:
        chat = int(chat)
    except (ValueError, Exception) as ef:
        if "invalid literal for int() with base 10:" in str(ef):
            chat = str(chat)
        else:
            return await message.reply_text(
                f"Got and exception {e}\n**Usage:**/chinfo [USERNAME|ID]"
            )

    m = await message.reply_text(
        f"Fetching chat info of chat from telegram's database....."
    )

    try:
        info_caption, photo_id = await chat_info(c, chat=chat)
    except Exception as e:
        await m.delete()
        await sleep()
        return await message.reply_text(f"**GOT AN ERROR:**\n {e}")
    if not photo_id:
        await m.delete()
        await sleep(2)
        return await message.reply_text(info_caption, disable_web_page_preview=True)

    photo = await c.download_media(photo_id)
    await m.delete()
    await sleep(2)
    try:
        await message.reply_photo(photo, caption=info_caption, quote=False)
    except MediaCaptionTooLong:
        x = await message.reply_photo(photo)
        try:
            await x.reply_text(info_caption)
        except EntityBoundsInvalid:
            await x.delete()
            await message.reply_text(info_caption)
        except RPCError as rpc:
            await message.reply_text(rpc)
            LOGGER.error(e)
            LOGGER.error(format_exc())
    except Exception as e:
        await message.reply_text(text=e)
        LOGGER.error(e)
        LOGGER.error(format_exc())

    os.remove(photo)

    return


__PLUGIN__ = "info"
__alt_name__ = [
    "info",
    "chinfo",
]

__HELP__ = """
**Information**

β€’ /info - To get info about the user
β€’ /chinfo - To get info about the chat
"""