From 40c4cf3164dd58829d0d341db80711b995be5544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=2E=E5=B1=B1=E5=B2=AD=E5=B1=85=E5=AE=A4?= Date: Mon, 24 Jan 2022 18:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`antichannelmsg`=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E7=85=A7=E4=BB=A5=E9=A2=91=E9=81=93=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E4=BA=BA=E6=95=B0=E8=BF=9B=E8=A1=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=B9=B6=E5=B0=81=E7=A6=81=20(#209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 洛水.山岭居室 Co-authored-by: Sam <25792361+sam01101@users.noreply.github.com> --- antichannelmsg.py | 36 +++++++++++++++++++++++++++++++++++- list.json | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/antichannelmsg.py b/antichannelmsg.py index ef4a186..97cf8dd 100644 --- a/antichannelmsg.py +++ b/antichannelmsg.py @@ -9,7 +9,7 @@ from pagermaid.listener import listener @listener(is_plugin=False, outgoing=True, command=alias_command('antichannelmsg'), description='开启对话的自动删除频道消息并且封禁频道功能,需要 Redis', - parameters="|status>") + parameters="|filter |status>") async def anti_channel_msg(context): if not redis_status(): await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}") @@ -52,6 +52,14 @@ async def anti_channel_msg(context): data.append(str(channel_data.full_chat.id)) redis.set("antichannelmsg." + str(context.chat_id), " ".join(data)) await context.edit("添加频道到白名单成功。") + elif context.parameter[0] == "filter": + try: + filter_int = int(context.parameter[1]) + except (IndexError, ValueError): + return await context.edit("输入错误。") + redis.set("antichannelmsg.filter:" + str(context.chat_id), str(filter_int)) + await context.edit(f"添加过滤成功,即群组 {str(context.chat_id)} 需要大于" + f" {str(filter_int)} 订阅人数的频道才能发言,否则会遭到删除并封禁。") elif context.parameter[0] == "status": if redis.get("antichannelmsg." + str(context.chat_id)): await context.edit('当前对话存在于自动删除频道消息并且封禁频道功能列表中。') @@ -74,6 +82,28 @@ async def auto_process_channel_msg(context): data = redis.get("antichannelmsg." + str(context.chat_id)) if not data: return + filter_data = redis.get("antichannelmsg.filter:" + str(context.chat_id)) + if filter_data is not None: + participants_count = redis.get("antichannelmsg.participants_count:" + str(context.chat_id)) + if participants_count is None: + expire = 300 + try: + channel_data = await bot(GetFullChannelRequest(int(context.sender.id))) + participants_count = channel_data.full_chat.participants_count + expire = 3600 + except: # noqa + participants_count = 0 + redis.set("antichannelmsg.participants_count:" + str(context.chat_id), + participants_count, ex=expire) + else: + try: + participants_count = int(participants_count) + except ValueError: + participants_count = 0 + try: + filter_int = int(filter_data) + except ValueError: + filter_int = -1 try: if not isinstance(context.sender, Channel): return @@ -81,6 +111,10 @@ async def auto_process_channel_msg(context): # 白名单 if str(context.sender.id) in data: return + # 频道订阅人数检测 + if filter_data is not None and (filter_int != -1 and participants_count >= filter_int): + return + # 删除消息,封禁频道 try: await context.delete() diff --git a/list.json b/list.json index 9e7b909..c7b417e 100644 --- a/list.json +++ b/list.json @@ -692,7 +692,7 @@ }, { "name": "antichannelmsg", - "version": "1.01", + "version": "1.02", "section": "chat", "maintainer": "xtaodada", "size": "4.8 kb",