Spaces:
Runtime error
Runtime error
File size: 6,714 Bytes
78b07ad |
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 |
import time
from pyrogram import Client
from pyrogram.enums import ChatMemberStatus, ChatType
from pyrogram.raw.functions.channels import GetAdminedPublicChannels
from pyrogram.raw.functions.users import GetFullUser
from pyrogram.types import Message
from Hellbot.functions.formatter import readable_time
from Hellbot.functions.templates import statistics_templates, user_info_templates
from . import HelpMenu, Symbols, hellbot, on_message
@on_message("count", allow_stan=True)
async def count_stats(client: Client, message: Message):
hell = await hellbot.edit(message, "Processing...")
bots = 0
users = 0
groups = 0
channels = 0
super_groups = 0
async for dialog in client.get_dialogs():
if dialog.chat.type == ChatType.BOT:
bots += 1
elif dialog.chat.type == ChatType.PRIVATE:
users += 1
elif dialog.chat.type == ChatType.GROUP:
groups += 1
elif dialog.chat.type == ChatType.SUPERGROUP:
super_groups += 1
elif dialog.chat.type == ChatType.CHANNEL:
channels += 1
else:
pass
total = bots + users + groups + super_groups + channels
await hell.edit(
f"**{client.me.mention}'π πΌππΊππ πΌππππ:**\n\n"
f" **{Symbols.anchor} π―ππππΊππΎ:** `{users}`\n"
f" **{Symbols.anchor} π¦πππππ:** `{groups}`\n"
f" **{Symbols.anchor} π²πππΎππ¦πππππ:** `{super_groups}`\n"
f" **{Symbols.anchor} π’ππΊπππΎπ
π:** `{channels}`\n"
f" **{Symbols.anchor} π‘πππ:** `{bots}`\n\n"
f"**{Symbols.triangle_right} π³πππΊπ
:** `{total}`\n"
)
@on_message("stats", allow_stan=True)
async def mystats(client: Client, message: Message):
hell = await hellbot.edit(message, "Processing...")
bots = 0
ch_admin = 0
ch_owner = 0
channels = 0
gc_admin = 0
gc_owner = 0
groups = 0
unread_mention = 0
unread_msg = 0
users = 0
start = time.time()
async for dialog in client.get_dialogs():
if dialog.chat.type == ChatType.CHANNEL:
meInChat = await dialog.chat.get_member(client.me.id)
channels += 1
if meInChat.status == ChatMemberStatus.OWNER:
ch_owner += 1
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
ch_admin += 1
elif dialog.chat.type == ChatType.GROUP:
meInChat = await dialog.chat.get_member(client.me.id)
groups += 1
if meInChat.status == ChatMemberStatus.OWNER:
gc_owner += 1
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
gc_admin += 1
elif dialog.chat.type == ChatType.SUPERGROUP:
meInChat = await dialog.chat.get_member(client.me.id)
groups += 1
if meInChat.status == ChatMemberStatus.OWNER:
gc_owner += 1
elif meInChat.status == ChatMemberStatus.ADMINISTRATOR:
gc_admin += 1
elif dialog.chat.type == ChatType.PRIVATE:
users += 1
elif dialog.chat.type == ChatType.BOT:
bots += 1
unread_mention += dialog.unread_mentions_count
unread_msg += dialog.unread_messages_count
time_taken = readable_time(int(time.time() - start)) or "0 seconds"
await hell.edit(
await statistics_templates(
name=client.me.mention,
channels=channels,
ch_admin=ch_admin,
ch_owner=ch_owner,
groups=groups,
gc_admin=gc_admin,
gc_owner=gc_owner,
users=users,
bots=bots,
unread_msg=unread_msg,
unread_mention=unread_mention,
time_taken=time_taken,
)
)
@on_message("reserved", allow_stan=True)
async def reserved(client: Client, message: Message):
hell = await hellbot.edit(message, "Processing...")
result = await client.invoke(GetAdminedPublicChannels())
outStr = f"π **{client.me.mention}'π ππΎππΎπππΎπ½ πππΎπππΊππΎπ:**\n\n"
for chat in result.chats:
f" {Symbols.bullet} {chat.title} - **{chat.username}**\n"
await hell.edit(outStr)
@on_message("info", allow_stan=True)
async def userInfo(client: Client, message: Message):
if not message.reply_to_message:
if len(message.command) < 2:
return await hellbot.error(message, "Reply to a user or give username/id to get their info.")
try:
user = await client.get_users(message.command[1])
except Exception as e:
return await hellbot.error(message, str(e))
else:
user = message.reply_to_message.from_user
hell = await hellbot.edit(message, f"Getting info of {user.mention}...")
try:
resolved = await client.resolve_peer(user.id)
fullUser = await client.invoke(GetFullUser(id=resolved))
bio = fullUser.about
except:
bio = None
total_pfp = await client.get_chat_photos_count(user.id)
common_chats = len(await user.get_common_chats())
user_info = await user_info_templates(
mention=user.mention,
firstName=user.first_name,
lastName=user.last_name,
userId=user.id,
bio=bio,
dcId=user.dc_id,
totalPictures=total_pfp,
isRestricted=user.is_restricted,
isVerified=user.is_verified,
isBot=user.is_bot,
commonGroups=common_chats,
)
if user.photo:
async for photo in client.get_chat_photos(user.id, 1):
await hell.delete()
await client.send_photo(
message.chat.id,
photo.file_id,
caption=user_info,
reply_to_message_id=message.id,
disable_notification=True,
)
return
else:
await hell.edit(user_info, disable_web_page_preview=True)
HelpMenu("statistics").add(
"count", None, "A brief overview of the number of chats I am in."
).add(
"stats", None, "A detailed overview of the number of chats I am in."
).add(
"reserved", None, "List of all the public usernames in my possession."
).add(
"info", "<reply> or <username/id>", "Get the user's detailed info.", "info @ForGo10God"
).info(
"Statistics Module"
).done()
|