From 12465bb9d72e3ec91725139fea629cd0d64bd448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=90=E6=B4=9B=E5=91=90?= Date: Thu, 23 Jun 2022 23:41:03 +0800 Subject: [PATCH] =?UTF-8?q?premium=20dc=20=E4=BF=AE=E5=A4=8D=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dc/main.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ list.json | 18 +++++++++++++---- premium/main.py | 25 ++++++++++++------------ 3 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 dc/main.py diff --git a/dc/main.py b/dc/main.py new file mode 100644 index 0000000..577dcbb --- /dev/null +++ b/dc/main.py @@ -0,0 +1,51 @@ +# -*- coding: UTF-8 -*- +''' +@File :main.py +@Author :汐洛 @guimc233 +@Date :2022/6/23 2:49 +''' + +from pyrogram import Client +from pagermaid.listener import listener +from pagermaid.utils import Message +from pyrogram.enums import ParseMode + +@listener(command="dc", + description="查看本群dc分布, 查看你回复的人在哪个dc") +async def dc(bot: Client, context: Message): + context = await context.edit("Please wait...") + if context.reply_to_message: + user = ( + context.reply_to_message.from_user + or context.reply_to_message.sender_chat + ) + if not user: + return await context.edit("出错啦!") + try: + return await context.edit(f"您所在的位置: DC{user.dc_id}") + except: + return await context.edit("无法查询! 您是否设置了头像呢?我是否可以看到你的头像呢?") + count = await bot.get_chat_members_count(context.chat.id) + if count >= 10000 and context.arguments != "force": + return await context.edit("太...太多人了... 我会...会...会坏掉的...\n\n如果您执意要运行的的话,您可以使用指令 ,dc force") + users = bots_deleted = 0 + dc_ids = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "failed": 0} + async for m in bot.get_chat_members(context.chat.id, limit=9999): + if not m.user.is_bot and not m.user.is_deleted: + users += 1 + try: + dc_ids[str(m.user.dc_id)] += 1 + except: + dc_ids["failed"] += 1 + else: + bots_deleted += 1 + await context.edit(f"""DC: +> DC1用户: **{dc_ids["1"]}** 分遗产占比: **{round((dc_ids["1"]/users)*100, 2)}%** +> DC2用户: **{dc_ids["2"]}** 分遗产占比: **{round((dc_ids["2"]/users)*100, 2)}%** +> DC3用户: **{dc_ids["3"]}** 分遗产占比: **{round((dc_ids["3"]/users)*100, 2)}%** +> DC4用户: **{dc_ids["4"]}** 分遗产占比: **{round((dc_ids["4"]/users)*100, 2)}%** +> DC5用户: **{dc_ids["5"]}** 分遗产占比: **{round((dc_ids["5"]/users)*100, 2)}%** +> 无法获取在哪个DC的用户: **{dc_ids["failed"]}** +> 已自动过滤掉 **{bots_deleted}** 个 Bot / 死号 + +{'***请注意: 由于tg限制 我们只能遍历前10k人 此次获得到的数据并不完整***' if count >= 10000 else ''}""", parse_mode = ParseMode.MARKDOWN) diff --git a/list.json b/list.json index 7f85647..1d0870b 100644 --- a/list.json +++ b/list.json @@ -192,13 +192,13 @@ }, { "name": "premium", - "version": "1.001", + "version": "1.002", "section": "chat", "maintainer": "xiluo", - "size": "3.2 kb", + "size": "2.0 kb", "supported": true, - "des-short": "列出本群premium用户数量 列出本群dc分布", - "des": "列出本群premium用户数量(指令: ,premium) \n列出本群dc分布/查看某个人所在的dc服务器(指令: ,dc)" + "des-short": "列出本群premium用户数量", + "des": "列出本群premium用户数量(指令: ,premium)" }, { "name": "autochangename", @@ -209,6 +209,16 @@ "supported": true, "des-short": "自动更新 last_name 为时间等。", "des": "每 30 秒自动更新 last_name 为时间等小玩意。" + }, + { + "name": "dc", + "version": "1.002", + "section": "chat", + "maintainer": "xiluo", + "size": "2.3 kb", + "supported": true, + "des-short": "列出本群dc分布/查看某个人所在的dc服务器", + "des": "列出本群dc分布/查看某个人所在的dc服务器(指令: ,dc)" } ] } diff --git a/premium/main.py b/premium/main.py index 390e45e..2ec4aac 100644 --- a/premium/main.py +++ b/premium/main.py @@ -2,7 +2,7 @@ ''' @File :main.py @Author :汐洛 @guimc233 -@Date :2022/6/23 2:49 +@Date :2022/6/23 21:57 ''' from pyrogram import Client @@ -15,11 +15,11 @@ from pyrogram.enums import ChatMemberStatus, ParseMode description="分遗产咯") async def premium(bot: Client, context: Message): context = await context.edit("Please wait...") - premium_users = 0 - users = 0 - premium_admins = 0 - admins = 0 + premium_users = users = admins = premium_admins = bots_deleted = 0 dc_ids = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "failed": 0} + count = await bot.get_chat_members_count(context.chat.id) + if count >= 10000 and context.arguments != "force": + return await context.edit("太...太多人了... 我会...会...会坏掉的...\n\n如果您执意要运行的的话,您可以使用指令 ,premium force") async for m in bot.get_chat_members(context.chat.id): if not m.user.is_bot and not m.user.is_deleted: users += 1 @@ -33,15 +33,16 @@ async def premium(bot: Client, context: Message): premium_admins += 1 if m.status in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]: admins += 1 - admin_part = 0 - if admins == 0: - admin_part = "这个群没有管理吗???" - else: - admin_part = round((premium_admins/admins)*100, 2) + else: + bots_deleted += 1 await context.edit(f"""**分遗产咯** 管理员: -> 大会员: **{premium_admins}** / 总管理数: **{admins}** 分遗产占比: **{admin_part}%** +> 大会员: **{premium_admins}** / 总管理数: **{admins}** 分遗产占比: **{round((premium_admins/admins)*100, 2) if admins != 0 else '你群管理员全死号?',}%** 用户: -> 大会员: **{premium_users}** / 总用户数: **{users}** 分遗产占比: **{round((premium_users/users)*100, 2)}%**""", parse_mode = ParseMode.MARKDOWN) +> 大会员: **{premium_users}** / 总用户数: **{users}** 分遗产占比: **{round((premium_users/users)*100, 2)}%** + +> 已自动过滤掉 **{bots_deleted}** 个 Bot / 死号 + +{'***请注意: 由于tg限制 我们只能遍历前10k人 此次获得到的数据并不完整***' if count >= 10000 else ''}""", parse_mode = ParseMode.MARKDOWN)