From 8271821071c86d42a232c76ad8dc7c223e9732a3 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 13 Jul 2021 20:00:09 +0800 Subject: [PATCH] =?UTF-8?q?unbanby=20=E6=9F=A5=E8=AF=A2/=E8=A7=A3=E9=99=A4?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E4=B8=AD=E8=A2=AB=E6=89=80=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=89=80=E5=B0=81=E7=A6=81=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fuckmember.py | 4 +-- list.json | 10 ++++++++ unbanby.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 unbanby.py diff --git a/fuckmember.py b/fuckmember.py index 4475835..9049ef7 100644 --- a/fuckmember.py +++ b/fuckmember.py @@ -3,7 +3,7 @@ from pagermaid.utils import alias_command from telethon.tl.types import ChannelParticipantsAdmins from telethon.errors.rpcerrorlist import UserAdminInvalidError from telethon.errors.rpcerrorlist import FloodWaitError -from time import sleep +from asyncio import sleep from random import uniform @@ -64,7 +64,7 @@ async def fuck_member(context): # Wait flood secs await context.edit(f'触发 Flood ,暂停 {e.seconds + uniform(0.5, 1.0)} 秒。') try: - sleep(e.seconds + uniform(0.5, 1.0)) + await sleep(e.seconds + uniform(0.5, 1.0)) except Exception as e: print(f"Wait flood error: {e}") return diff --git a/list.json b/list.json index 1ea7ee6..56a8b23 100644 --- a/list.json +++ b/list.json @@ -599,6 +599,16 @@ "supported": true, "des-short": "查找/清理群组中所有潜水超过一定天数的成员。", "des": "查找/清理群组中所有潜水超过 n 天的成员。(n>=7)。命令:fuckmember 。" + }, + { + "name": "unbanby", + "version": "1.0", + "section": "daily", + "maintainer": "xtaodada", + "size": "2.8 kb", + "supported": true, + "des-short": "查询/解除群组中被所回复用户所封禁的用户。", + "des": "查询/解除群组中被所回复用户所封禁的用户。命令:unbanby 。" } ] } diff --git a/unbanby.py b/unbanby.py new file mode 100644 index 0000000..15f4140 --- /dev/null +++ b/unbanby.py @@ -0,0 +1,70 @@ +from pagermaid.listener import listener +from pagermaid.utils import alias_command +from telethon.tl.types import ChannelParticipantsKicked, ChannelParticipantsAdmins +from telethon.errors.rpcerrorlist import UserAdminInvalidError +from telethon.errors.rpcerrorlist import FloodWaitError +from asyncio import sleep +from random import uniform + + +@listener(is_plugin=False, outgoing=True, command=alias_command("unbanby"), + description='查询/解除群组中被所回复用户所封禁的用户。', + parameters="") +async def unban_by_bot(context): + if not context.is_group: + await context.edit('请在群组中运行。') + return + reply = await context.get_reply_message() + if not reply: + await context.edit('请回复一个用户。') + return + # 读取模式 + unban_mode = False + if len(context.parameter) == 1: + unban_mode = True + text = f'查找被 Ta 封禁的用户中。' + if unban_mode: + text += '\n移除中。。。' + await context.edit(text) + # 读取权限 + count, members, members_count = 0, 0, 0 + admins = await context.client.get_participants(context.chat, filter=ChannelParticipantsAdmins) + if context.sender in admins: + user = admins[admins.index(context.sender)] + if not user.participant.admin_rights.ban_users: + await context.edit('无封禁用户权限,停止查询。') + return + # 遍历列表 + async for x in context.client.iter_participants(context.chat, filter=ChannelParticipantsKicked): + members += 1 + if x.participant.kicked_by == reply.sender_id: + count += 1 + if unban_mode: + try: + await context.client.edit_permissions(context.chat, x) + except FloodWaitError as e: + # Wait flood secs + await context.edit(f'触发 Flood ,暂停 {e.seconds + uniform(0.5, 1.0)} 秒。') + try: + await sleep(e.seconds + uniform(0.5, 1.0)) + except Exception as e: + print(f"Wait flood error: {e}") + return + except UserAdminInvalidError: + await context.edit('无管理员权限,停止查询。') + return + # 每一百人修改一次 + if members == 100: + members_count += 1 + members = 0 + await context.edit(text + f'\n已查找 {members_count * 100} 人。') + text = '' + if count > 0: + text += f'查找到了 {count} 个被 Ta 封禁的用户。\n' + if unban_mode: + text += '解除完毕。' + else: + text += f'使用 `-unbanby yes` 开始解除封禁' + else: + text = f'没有发现被 Ta 封禁的用户呢。' + await context.edit(text)