From abaa1a518d67be79b018b7033355bec490a61ff1 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 11 Jul 2021 22:57:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fuckadmin=20=E5=88=97=E5=87=BA?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E4=B8=AD=E6=89=80=E6=9C=89=E6=BD=9C=E6=B0=B4?= =?UTF-8?q?=E8=B6=85=E8=BF=87=20n=20=E5=A4=A9=E7=9A=84=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fuckadmin.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ list.json | 10 +++++++ 2 files changed, 91 insertions(+) create mode 100644 fuckadmin.py diff --git a/fuckadmin.py b/fuckadmin.py new file mode 100644 index 0000000..f161e15 --- /dev/null +++ b/fuckadmin.py @@ -0,0 +1,81 @@ +from pagermaid.listener import listener +from pagermaid.utils import alias_command +from telethon.tl.types import ChannelParticipantsAdmins + + +def eval_time(context, msg, day): + now = context.date + old = msg.date + between = (now - old).seconds + require_sec = day * 86400 + if between < require_sec: + return None + minute, sec = divmod(between, 60) + hour, minute = divmod(minute, 60) + day, hour = divmod(hour, 24) + month, day = divmod(day, 30) + year, month = divmod(month, 12) + if year > 0: + time = "%02d年%02d月%02d天%02d时%02d分%02d秒" % (year, month, day, hour, minute, sec) + elif month > 0: + time = "%02d月%02d天%02d时%02d分%02d秒" % (month, day, hour, minute, sec) + elif day > 0: + time = "%02d天%02d时%02d分%02d秒" % (day, hour, minute, sec) + elif hour > 0: + time = "%02d时%02d分%02d秒" % (hour, minute, sec) + elif minute > 0: + time = "%02d分%02d秒" % (minute, sec) + else: + time = f"{sec}秒" + return time + + +def mention_user(user): + if user.username: + mention = user.username + else: + mention = user.id + return f'`{user.first_name}` [`{mention}`]' + + +@listener(is_plugin=False, outgoing=True, command=alias_command("fuckadmin"), + description='列出群组中所有潜水超过 n 天的管理员。(n>=7)。', + parameters="") +async def fuck_admin(context): + if context.is_group: + pass + else: + await context.edit('请在群组中运行。') + return + await context.edit('遍历管理员中。') + # 读取天数 + text = '' + if len(context.parameter) == 1: + try: + day = int(context.parameter[0]) + if day < 7: + day = 7 + text += '由于输入的数据过小,时间自动设置为 7 天。\n' + except KeyError: + day = 7 + text += '由于输入的数据错误,时间自动设置为 7 天。\n' + else: + day = 7 + text += '由于未输入数据,时间自动设置为 7 天。\n' + text += f'查找潜水超过 {day} 天的管理员中。' + await context.edit(text) + # 获取管理员 + text = f'以下是潜水超过 {day} 天的管理员列表:\n\n' + msg = 0 + async for x in context.client.iter_participants(context.chat, filter=ChannelParticipantsAdmins): + async for message in context.client.iter_messages(context.chat_id, limit=1, from_user=x): + msg += 1 + time = eval_time(context, message, day) + if time: + text += f'{mention_user(x)} {time}\n' + break + if msg == 1: + msg = 0 + else: + text += f'{mention_user(x)} 从未发言\n' + await context.edit(text) diff --git a/list.json b/list.json index c5fc45c..b9bc1e1 100644 --- a/list.json +++ b/list.json @@ -569,6 +569,16 @@ "supported": true, "des-short": "列出所有属于自己的公开群组/频道。", "des": "列出所有属于自己的公开群组/频道。命令:listusernames 。" + }, + { + "name": "fuckadmin", + "version": "1.0", + "section": "daily", + "maintainer": "xtaodada", + "size": "2.7 kb", + "supported": true, + "des-short": "列出群组中所有潜水超过 n 天的管理员。", + "des": "列出群组中所有潜水超过 n 天的管理员。(n>=7)。命令:fuckadmin 。" } ] }