From 4805ecfd5035cb6b423894c140acbefc4d61136c Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 16 Jan 2022 20:43:13 +0800 Subject: [PATCH] =?UTF-8?q?dme=20=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dme.py | 64 +++---------------------------------------------------- list.json | 4 ++-- 2 files changed, 5 insertions(+), 63 deletions(-) diff --git a/dme.py b/dme.py index 702a735..80d47f8 100644 --- a/dme.py +++ b/dme.py @@ -1,70 +1,12 @@ """ Module to automate message deletion. """ -from asyncio import sleep -from pagermaid import log from pagermaid.listener import listener from pagermaid.utils import alias_command, lang +from pagermaid.modules.prune import selfprune @listener(is_plugin=False, outgoing=True, command=alias_command("dme"), description=lang('sp_des'), parameters=lang('sp_parameters')) -async def selfprune(context): +async def dme(context): """ Deletes specific amount of messages you sent. """ - msgs = [] - count_buffer = 0 - if not len(context.parameter) == 1: - if not context.reply_to_msg_id: - await context.edit(lang('arg_error')) - return - async for msg in context.client.iter_messages( - context.chat_id, - from_user="me", - min_id=context.reply_to_msg_id, - ): - msgs.append(msg) - count_buffer += 1 - if len(msgs) == 100: - await context.client.delete_messages(context.chat_id, msgs) - msgs = [] - if msgs: - await context.client.delete_messages(context.chat_id, msgs) - if count_buffer == 0: - await context.delete() - count_buffer += 1 - await log(f"{lang('prune_hint1')}{lang('sp_hint')} {str(count_buffer)} {lang('prune_hint2')}") - notification = await send_prune_notify(context, count_buffer, count_buffer) - await sleep(1) - await notification.delete() - return - try: - count = int(context.parameter[0]) - await context.delete() - except ValueError: - await context.edit(lang('arg_error')) - return - async for message in context.client.iter_messages(context.chat_id, from_user="me"): - if count_buffer == count: - break - msgs.append(message) - count_buffer += 1 - if len(msgs) == 100: - await context.client.delete_messages(context.chat_id, msgs) - msgs = [] - if msgs: - await context.client.delete_messages(context.chat_id, msgs) - await log(f"{lang('prune_hint1')}{lang('sp_hint')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}") - try: - notification = await send_prune_notify(context, count_buffer, count) - await sleep(1) - await notification.delete() - except ValueError: - pass - - -async def send_prune_notify(context, count_buffer, count): - return await context.client.send_message( - context.chat_id, - lang('spn_deleted') - + str(count_buffer) + " / " + str(count) - + lang('prune_hint2') - ) + await selfprune(context) diff --git a/list.json b/list.json index 538dbf7..9f42b0e 100644 --- a/list.json +++ b/list.json @@ -832,10 +832,10 @@ }, { "name": "dme", - "version": "1.2", + "version": "1.201", "section": "chat", "maintainer": "xtaodada", - "size": "4.3 kb", + "size": "0.4 kb", "supported": true, "des-short": "删除当前对话您发送的特定数量的消息。", "des": "删除当前对话您发送的特定数量的消息。"