Ufoptg commited on
Commit
47ad446
Β·
verified Β·
1 Parent(s): 6f1d26e

Update Hellbot/plugins/user/statistics.py

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