From 756b9a1131f0727ce22093659e7768e72dee7f68 Mon Sep 17 00:00:00 2001 From: yxkumad <46276046+yxkumad@users.noreply.github.com> Date: Mon, 24 Aug 2020 15:55:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20da=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- da.py | 40 ++++++++++++++++++++++++++++++++++++++++ list.json | 10 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 da.py diff --git a/da.py b/da.py new file mode 100644 index 0000000..2ff5331 --- /dev/null +++ b/da.py @@ -0,0 +1,40 @@ +from asyncio import sleep +from pagermaid import log +from pagermaid.listener import listener + +@listener(is_plugin=True, outgoing=True, command="da", + description="以此命令删除所有消息。(非群组管理员只删除自己的消息)", + parameters="") +async def prune(context): + if len(context.parameter) > 2 or len(context.parameter) == 0: + await context.edit("\n呜呜呜,请执行 `-da true` 来删除所有消息。") + return + if context.parameter[0] != "true": + await context.edit("\n呜呜呜,请执行 `-da true` 来删除所有消息。") + return + await context.edit('正在删除所有消息 . . .') + input_chat = await context.get_input_chat() + messages = [] + count = 0 + async for message in context.client.iter_messages(input_chat, min_id=1): + messages.append(message) + count += 1 + messages.append(1) + if len(messages) == 100: + await context.client.delete_messages(input_chat, messages) + messages = [] + + if messages: + await context.client.delete_messages(input_chat, messages) + await log(f"批量删除了 {str(count)} 条消息。") + notification = await send_prune_notify(context, count) + await sleep(.5) + await notification.delete() + +async def send_prune_notify(context, count): + return await context.client.send_message( + context.chat_id, + "批量删除了 " + + str(count) + + " 条消息。" + ) diff --git a/list.json b/list.json index 9da1fa8..828adf4 100644 --- a/list.json +++ b/list.json @@ -239,6 +239,16 @@ "supported": true, "des-short": "多网站随机获取ACG图", "des": "从几个不同的图库中随机获取二刺螈(bushi)ACG图片,基本都是手机尺寸的图。命令:acgm。" + }, + { + "name": "da", + "version": "1.0", + "section": "chat", + "maintainer": "yxkumad", + "size": "1.6 kb", + "supported": true, + "des-short": "删除所有信息", + "des": "删除所有信息(非群组管理员只删除自己的消息),需要二次确定(-da true)。命令:da" } ] }