dme 新版 dme

This commit is contained in:
xtaodada 2022-01-16 20:35:14 +08:00
parent 3062067446
commit 800acfb6bd
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 62 additions and 108 deletions

160
dme.py
View File

@ -1,126 +1,70 @@
""" Module to automate message deletion. """ """ Module to automate message deletion. """
from asyncio import sleep from asyncio import sleep
from os import path, remove from pagermaid import log
from os.path import exists
from PIL import Image, UnidentifiedImageError
from pagermaid import redis, log, redis_status
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import alias_command from pagermaid.utils import alias_command, lang
@listener(is_plugin=True, outgoing=True, command=alias_command("dme"), @listener(is_plugin=False, outgoing=True, command=alias_command("dme"),
description="编辑并删除当前对话您发送的特定数量的消息。限制:基于消息 ID 的 1000 条消息,大于 1000 " description=lang('sp_des'),
"条可能会触发删除消息过快限制。入群消息非管理员无法删除。(倒序)当数字足够大时即可实现删除所有消息。", parameters=lang('sp_parameters'))
parameters="<数量> [文本]") async def selfprune(context):
async def dme(context):
""" Deletes specific amount of messages you sent. """ """ Deletes specific amount of messages you sent. """
reply = await context.get_reply_message() msgs = []
if reply and reply.photo:
if exists('plugins/dme.jpg'):
remove('plugins/dme.jpg')
target_file = reply.photo
await context.client.download_media(
await context.get_reply_message(), file="plugins/dme.jpg"
)
await context.edit("替换图片设置完成。")
elif reply and reply.sticker:
if exists('plugins/dme.jpg'):
remove('plugins/dme.jpg')
await context.client.download_media(reply.media.document, file="plugins/dme.webp")
try:
im = Image.open("plugins/dme.webp")
except UnidentifiedImageError:
await context.edit("替换图片设置发生错误。")
return
im.save('plugins/dme.png', "png")
remove('plugins/dme.webp')
target_file = await context.client.upload_file('plugins/dme.png')
await context.edit("替换图片设置完成。")
elif path.isfile("plugins/dme.jpg"):
target_file = await context.client.upload_file('plugins/dme.jpg')
elif path.isfile("plugins/dme.png"):
target_file = await context.client.upload_file('plugins/dme.png')
else:
target_file = False
await context.edit("注意:没有图片进行替换。")
try:
count = int(context.parameter[0]) + 1
except ValueError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
except IndexError:
await context.edit("出错了呜呜呜 ~ 无效的参数。")
return
dme_msg = "别搁这防撤回了。。。"
if len(context.parameter) == 1:
if not redis_status():
pass
else:
try:
dme_msg = redis.get("dme_msg").decode()
except:
pass
elif len(context.parameter) == 2:
dme_msg = context.parameter[1]
if not redis_status():
pass
elif not dme_msg == str(count):
try:
redis.set("dme_msg", dme_msg)
except:
pass
count_buffer = 0 count_buffer = 0
try: if not len(context.parameter) == 1:
async for message in context.client.iter_messages(context.chat_id, from_user="me"): if not context.reply_to_msg_id:
if count_buffer == count: await context.edit(lang('arg_error'))
break return
if message.forward or message.via_bot or message.sticker or message.contact or message.poll or message.game or message.geo: async for msg in context.client.iter_messages(
pass context.chat_id,
elif message.text or message.voice: from_user="me",
if not message.text == dme_msg: min_id=context.reply_to_msg_id,
try: ):
await message.edit(dme_msg) msgs.append(msg)
except:
pass
elif message.document or message.photo or message.file or message.audio or message.video or message.gif:
if target_file:
if not message.text == dme_msg:
try:
await message.edit(dme_msg, file=target_file)
except:
pass
else:
if not message.text == dme_msg:
try:
await message.edit(dme_msg)
except:
pass
else:
pass
await message.delete()
count_buffer += 1 count_buffer += 1
except ValueError: if len(msgs) == 100:
try: await context.client.delete_messages(context.chat_id, msgs)
await context.edit('出错了呜呜呜 ~ 无法识别的对话') msgs = []
except: if msgs:
pass 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 return
count -= 1 try:
count_buffer -= 1 count = int(context.parameter[0])
await log(f"批量删除了自行发送的 {str(count_buffer)} / {str(count)} 条消息。") 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: try:
notification = await send_prune_notify(context, count_buffer, count) notification = await send_prune_notify(context, count_buffer, count)
except: await sleep(1)
return await notification.delete()
await sleep(.5) except ValueError:
await notification.delete() pass
async def send_prune_notify(context, count_buffer, count): async def send_prune_notify(context, count_buffer, count):
return await context.client.send_message( return await context.client.send_message(
context.chat_id, context.chat_id,
"删除了 " lang('spn_deleted')
+ str(count_buffer) + " / " + str(count) + str(count_buffer) + " / " + str(count)
+ " 条消息。" + lang('prune_hint2')
) )

View File

@ -829,6 +829,16 @@
"supported": true, "supported": true,
"des-short": "天天疯狂!", "des-short": "天天疯狂!",
"des": "随机输出KFC疯狂星期四文案。\n指令-crazy4" "des": "随机输出KFC疯狂星期四文案。\n指令-crazy4"
},
{
"name": "dme",
"version": "1.2",
"section": "chat",
"maintainer": "xtaodada",
"size": "4.3 kb",
"supported": true,
"des-short": "删除当前对话您发送的特定数量的消息。",
"des": "删除当前对话您发送的特定数量的消息。"
} }
] ]
} }