async def stats(event: NewMessage.Event) -> None: # pylint: disable = R0912, R0914, R0915 """Command to get stats about the account""" 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): 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 entity.creator or entity.admin_rights: 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' 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'__Took:__ {stop_time:.02f}s \n' await event.edit(response)
async def stats( event: NewMessage.Event ) -> None: # pylint: disable = R0912, R0914, R0915 """Command to get stats about the account""" waiting_message = await event.edit( 'Collecting stats. This might take a while.') 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 largest_group_member_count = 0 largest_group_with_admin = 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' 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'__Took:__ {stop_time:.02f}s \n' await event.edit(response)
async def fetch_info(event, full_chat, **kwargs): chat = full_chat.chats[0] show_all = kwargs.get('all', False) id_only = kwargs.get('id', False) show_general = kwargs.get('general', True) show_admins = kwargs.get('admins', False) show_bots = kwargs.get('bots', False) is_private = False if isinstance(chat, Channel) and chat.username: name = chat.title if chat.title else chat.username title = Bold("Chat Informations") elif chat.title: is_private = True title = Bold("Chat Informations") else: is_private = True title = Bold(f"Chat {chat.id}") if show_all: show_general = True show_admins = True show_bots = True elif id_only: return KeyValueItem(title, Code(str(chat.id))) admin_list = await list_admins(event) if show_general: exported_invite = full_chat.full_chat.exported_invite invite_link = exported_invite.link if isinstance( exported_invite, ChatInviteExported) else None admin_count = full_chat.full_chat.admins_count or len(admin_list) general = SubSection( KeyValueItem(" \tChat Id", Code(str(f"-100{chat.id}"))), KeyValueItem("Title", f"[{chat.title}](t.me/{chat.username})"), KeyValueItem("Private", Code(str(is_private))), KeyValueItem("Invite Link", Link(invite_link.split('/')[-1], invite_link)) if invite_link else None, KeyValueItem("Admins", Code(str(admin_count))), KeyValueItem("Online", Code(str(full_chat.full_chat.online_count))), KeyValueItem("Total", Code(str(full_chat.full_chat.participants_count)))) else: general = None if show_admins: admins = SubSection(Bold("Admins")) for admin in admin_list: admins.items.append(String(inline_mention(admin))) if not admins: admins.items.append(String("No Admins")) if show_bots: bots_list = await list_bots(event) bots = SubSection(Bold("Bots")) for bot in bots_list: bots.items.append(String(inline_mention(bot))) if not bots: bots.items.append(String("No Bots")) return TGDoc( Section(title, general if show_general else None, admins if show_admins else None, bots if show_bots else None))