Spaces:
Runtime error
Runtime error
Update Hellbot/plugins/user/statistics.py
Browse files- Hellbot/plugins/user/statistics.py +199 -195
Hellbot/plugins/user/statistics.py
CHANGED
@@ -1,195 +1,199 @@
|
|
1 |
-
import time
|
2 |
-
|
3 |
-
from pyrogram import Client
|
4 |
-
from pyrogram.enums import ChatMemberStatus, ChatType
|
5 |
-
from pyrogram.raw.functions.channels import GetAdminedPublicChannels
|
6 |
-
from pyrogram.raw.functions.users import GetFullUser
|
7 |
-
from pyrogram.types import Message
|
8 |
-
|
9 |
-
|
10 |
-
from Hellbot.functions.
|
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 |
-
f"
|
42 |
-
f" **{Symbols.anchor}
|
43 |
-
f" **{Symbols.anchor}
|
44 |
-
f" **{Symbols.anchor}
|
45 |
-
f" **{Symbols.anchor}
|
46 |
-
f"**{Symbols.
|
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 |
-
return await hellbot.error(message,
|
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 |
-
).add(
|
190 |
-
"
|
191 |
-
).add(
|
192 |
-
"
|
193 |
-
).
|
194 |
-
"
|
195 |
-
).
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
|
3 |
+
from pyrogram import Client
|
4 |
+
from pyrogram.enums import ChatMemberStatus, ChatType
|
5 |
+
from pyrogram.raw.functions.channels import GetAdminedPublicChannels
|
6 |
+
from pyrogram.raw.functions.users import GetFullUser
|
7 |
+
from pyrogram.types import Message
|
8 |
+
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
|
9 |
+
|
10 |
+
from Hellbot.functions.formatter import readable_time
|
11 |
+
from Hellbot.functions.templates import statistics_templates, user_info_templates
|
12 |
+
|
13 |
+
from . import HelpMenu, Symbols, hellbot, on_message
|
14 |
+
|
15 |
+
|
16 |
+
@on_message("count", allow_stan=True)
|
17 |
+
async def count_stats(client: Client, message: Message):
|
18 |
+
hell = await hellbot.edit(message, "Processing...")
|
19 |
+
bots = 0
|
20 |
+
users = 0
|
21 |
+
groups = 0
|
22 |
+
channels = 0
|
23 |
+
super_groups = 0
|
24 |
+
|
25 |
+
async for dialog in client.get_dialogs():
|
26 |
+
if dialog.chat.type == ChatType.BOT:
|
27 |
+
bots += 1
|
28 |
+
elif dialog.chat.type == ChatType.PRIVATE:
|
29 |
+
users += 1
|
30 |
+
elif dialog.chat.type == ChatType.GROUP:
|
31 |
+
groups += 1
|
32 |
+
elif dialog.chat.type == ChatType.SUPERGROUP:
|
33 |
+
super_groups += 1
|
34 |
+
elif dialog.chat.type == ChatType.CHANNEL:
|
35 |
+
channels += 1
|
36 |
+
else:
|
37 |
+
pass
|
38 |
+
|
39 |
+
total = bots + users + groups + super_groups + channels
|
40 |
+
await hell.edit(
|
41 |
+
f"**{client.me.mention}'π πΌππΊππ πΌππππ:**\n\n"
|
42 |
+
f" **{Symbols.anchor} π―ππππΊππΎ:** `{users}`\n"
|
43 |
+
f" **{Symbols.anchor} π¦πππππ:** `{groups}`\n"
|
44 |
+
f" **{Symbols.anchor} π²πππΎππ¦πππππ:** `{super_groups}`\n"
|
45 |
+
f" **{Symbols.anchor} π’ππΊπππΎπ
π:** `{channels}`\n"
|
46 |
+
f" **{Symbols.anchor} π‘πππ:** `{bots}`\n\n"
|
47 |
+
f"**{Symbols.triangle_right} π³πππΊπ
:** `{total}`\n"
|
48 |
+
)
|
49 |
+
|
50 |
+
|
51 |
+
@on_message("stats", allow_stan=True)
|
52 |
+
async def mystats(client: Client, message: Message):
|
53 |
+
hell = await hellbot.edit(message, "Processing...")
|
54 |
+
bots = 0
|
55 |
+
ch_admin = 0
|
56 |
+
ch_owner = 0
|
57 |
+
channels = 0
|
58 |
+
gc_admin = 0
|
59 |
+
gc_owner = 0
|
60 |
+
groups = 0
|
61 |
+
unread_mention = 0
|
62 |
+
unread_msg = 0
|
63 |
+
users = 0
|
64 |
+
|
65 |
+
start = time.time()
|
66 |
+
try:
|
67 |
+
async for dialog in client.get_dialogs():
|
68 |
+
if dialog.chat.type == ChatType.CHANNEL:
|
69 |
+
meInChat = await dialog.chat.get_member(client.me.id)
|
70 |
+
channels += 1
|
71 |
+
if meInChat.status == ChatMemberStatus.OWNER:
|
72 |
+
ch_owner += 1
|
73 |
+
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
|
74 |
+
ch_admin += 1
|
75 |
+
|
76 |
+
elif dialog.chat.type == ChatType.GROUP:
|
77 |
+
meInChat = await dialog.chat.get_member(client.me.id)
|
78 |
+
groups += 1
|
79 |
+
if meInChat.status == ChatMemberStatus.OWNER:
|
80 |
+
gc_owner += 1
|
81 |
+
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
|
82 |
+
gc_admin += 1
|
83 |
+
|
84 |
+
elif dialog.chat.type == ChatType.SUPERGROUP:
|
85 |
+
meInChat = await dialog.chat.get_member(client.me.id)
|
86 |
+
groups += 1
|
87 |
+
if meInChat.status == ChatMemberStatus.OWNER:
|
88 |
+
gc_owner += 1
|
89 |
+
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
|
90 |
+
gc_admin += 1
|
91 |
+
|
92 |
+
elif dialog.chat.type == ChatType.PRIVATE:
|
93 |
+
users += 1
|
94 |
+
|
95 |
+
elif dialog.chat.type == ChatType.BOT:
|
96 |
+
bots += 1
|
97 |
+
except UserNotParticipant:
|
98 |
+
pass
|
99 |
+
|
100 |
+
unread_mention += dialog.unread_mentions_count
|
101 |
+
unread_msg += dialog.unread_messages_count
|
102 |
+
|
103 |
+
time_taken = readable_time(int(time.time() - start)) or "0 seconds"
|
104 |
+
|
105 |
+
await hell.edit(
|
106 |
+
await statistics_templates(
|
107 |
+
name=client.me.mention,
|
108 |
+
channels=channels,
|
109 |
+
ch_admin=ch_admin,
|
110 |
+
ch_owner=ch_owner,
|
111 |
+
groups=groups,
|
112 |
+
gc_admin=gc_admin,
|
113 |
+
gc_owner=gc_owner,
|
114 |
+
users=users,
|
115 |
+
bots=bots,
|
116 |
+
unread_msg=unread_msg,
|
117 |
+
unread_mention=unread_mention,
|
118 |
+
time_taken=time_taken,
|
119 |
+
)
|
120 |
+
)
|
121 |
+
|
122 |
+
|
123 |
+
@on_message("reserved", allow_stan=True)
|
124 |
+
async def reserved(client: Client, message: Message):
|
125 |
+
hell = await hellbot.edit(message, "Processing...")
|
126 |
+
result = await client.invoke(GetAdminedPublicChannels())
|
127 |
+
|
128 |
+
outStr = f"π **{client.me.mention}'π ππΎππΎπππΎπ½ πππΎπππΊππΎπ:**\n\n"
|
129 |
+
for chat in result.chats:
|
130 |
+
f" {Symbols.bullet} {chat.title} - **{chat.username}**\n"
|
131 |
+
|
132 |
+
await hell.edit(outStr)
|
133 |
+
|
134 |
+
|
135 |
+
@on_message("info", allow_stan=True)
|
136 |
+
async def userInfo(client: Client, message: Message):
|
137 |
+
if not message.reply_to_message:
|
138 |
+
if len(message.command) < 2:
|
139 |
+
return await hellbot.error(message, "Reply to a user or give username/id to get their info.")
|
140 |
+
try:
|
141 |
+
user = await client.get_users(message.command[1])
|
142 |
+
except Exception as e:
|
143 |
+
return await hellbot.error(message, str(e))
|
144 |
+
else:
|
145 |
+
user = message.reply_to_message.from_user
|
146 |
+
|
147 |
+
hell = await hellbot.edit(message, f"Getting info of {user.mention}...")
|
148 |
+
|
149 |
+
try:
|
150 |
+
resolved = await client.resolve_peer(user.id)
|
151 |
+
fullUser = await client.invoke(GetFullUser(id=resolved))
|
152 |
+
bio = fullUser.about
|
153 |
+
except:
|
154 |
+
bio = None
|
155 |
+
|
156 |
+
total_pfp = await client.get_chat_photos_count(user.id)
|
157 |
+
common_chats = len(await user.get_common_chats())
|
158 |
+
|
159 |
+
user_info = await user_info_templates(
|
160 |
+
mention=user.mention,
|
161 |
+
firstName=user.first_name,
|
162 |
+
lastName=user.last_name,
|
163 |
+
userId=user.id,
|
164 |
+
bio=bio,
|
165 |
+
dcId=user.dc_id,
|
166 |
+
totalPictures=total_pfp,
|
167 |
+
isRestricted=user.is_restricted,
|
168 |
+
isVerified=user.is_verified,
|
169 |
+
isBot=user.is_bot,
|
170 |
+
commonGroups=common_chats,
|
171 |
+
)
|
172 |
+
|
173 |
+
if user.photo:
|
174 |
+
async for photo in client.get_chat_photos(user.id, 1):
|
175 |
+
await hell.delete()
|
176 |
+
await client.send_photo(
|
177 |
+
message.chat.id,
|
178 |
+
photo.file_id,
|
179 |
+
caption=user_info,
|
180 |
+
reply_to_message_id=message.id,
|
181 |
+
disable_notification=True,
|
182 |
+
)
|
183 |
+
return
|
184 |
+
else:
|
185 |
+
await hell.edit(user_info, disable_web_page_preview=True)
|
186 |
+
|
187 |
+
|
188 |
+
|
189 |
+
HelpMenu("statistics").add(
|
190 |
+
"count", None, "A brief overview of the number of chats I am in."
|
191 |
+
).add(
|
192 |
+
"stats", None, "A detailed overview of the number of chats I am in."
|
193 |
+
).add(
|
194 |
+
"reserved", None, "List of all the public usernames in my possession."
|
195 |
+
).add(
|
196 |
+
"info", "<reply> or <username/id>", "Get the user's detailed info.", "info @ForGo10God"
|
197 |
+
).info(
|
198 |
+
"Statistics Module"
|
199 |
+
).done()
|