-
Notifications
You must be signed in to change notification settings - Fork 5
/
count.py
106 lines (95 loc) · 3.95 KB
/
count.py
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
import time
from telethon.events import NewMessage
from telethon.tl.custom import Dialog
from telethon.tl.types import Channel, Chat, User
from ULTRA.utils import admin_cmd, edit_or_reply, sudo_cmd
from ULTRA import CMD_HELP
@bot.on(admin_cmd(pattern="stats$"))
@bot.on(sudo_cmd(pattern="stats$", allow_sudo=True))
async def stats(
event: NewMessage.Event,
) -> None: # pylint: disable = R0912, R0914, R0915
"""Command to get stats about the account"""
hell = await edit_or_reply(event, "`Collecting stats...`")
start_time = time.time()
private_chats = 0
bots = 0
groups = 0
broadcast_channels = 0
admin_in_groups = 0
creator_in_groups = 0
admin_in_broadcast_channels = 0
creator_in_channels = 0
unread_mentions = 0
unread = 0
dialog: Dialog
async for dialog in event.client.iter_dialogs():
entity = dialog.entity
if isinstance(entity, Channel):
# participants_count = (await event.get_participants(dialog,
# limit=0)).total
if entity.broadcast:
broadcast_channels += 1
if entity.creator or entity.admin_rights:
admin_in_broadcast_channels += 1
if entity.creator:
creator_in_channels += 1
elif entity.megagroup:
groups += 1
# if participants_count > largest_group_member_count:
# largest_group_member_count = participants_count
if entity.creator or entity.admin_rights:
# if participants_count > largest_group_with_admin:
# largest_group_with_admin = participants_count
admin_in_groups += 1
if entity.creator:
creator_in_groups += 1
elif isinstance(entity, User):
private_chats += 1
if entity.bot:
bots += 1
elif isinstance(entity, Chat):
groups += 1
if entity.creator or entity.admin_rights:
admin_in_groups += 1
if entity.creator:
creator_in_groups += 1
unread_mentions += dialog.unread_mentions_count
unread += dialog.unread_count
stop_time = time.time() - start_time
full_name = inline_mention(await event.client.get_me())
response = f'🔰**Stats for {full_name}**🔰\n\n'
response += f'🔱 **Private Chats:** {private_chats} \n'
response += f'🔸 `Users: {private_chats - bots}` \n'
response += f'🔹 `Bots: {bots}` \n'
response += f'🔱 **Groups:** {groups} \n'
response += f'🔱 **Channels:** {broadcast_channels} \n'
response += f'☣️ **Admin in Groups:** {admin_in_groups} \n'
response += f'🔹 `Creator: {creator_in_groups}` \n'
response += f'🔸 `Admin Rights: {admin_in_groups - creator_in_groups}` \n'
response += f'☣️ **Admin in Channels:** {admin_in_broadcast_channels} \n'
response += f'🔸 `Creator: {creator_in_channels}` \n'
response += f'🔹 `Admin Rights: {admin_in_broadcast_channels - creator_in_channels}` \n'
response += f'🔱 **Unread:** {unread} \n'
response += f'🔱 **Unread Mentions:** {unread_mentions} \n\n'
response += f'☣️ __It Took:__ {stop_time:.02f}s \n'
response += f'📌 **From The DataBase Of** :- [LEGEND BOT](https://github.com/legendx22/LEGEND-BOT)'
await hell.edit(response)
def make_mention(user):
if user.username:
return f"@{user.username}"
return inline_mention(user)
def inline_mention(user):
full_name = user_full_name(user) or "No Name"
return f"[{full_name}](tg://user?id={user.id})"
def user_full_name(user):
names = [user.first_name, user.last_name]
names = [i for i in list(names) if i]
return " ".join(names)
CMD_HELP.update(
{
"stat": "**Plugin : **`stat`\
\n\n**Syntax : **`.stat`\
\n**Function : **Shows you the count of your groups, channels, private chats...etc"
}
)