mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-21 19:18:17 +00:00
dme 新版 dme
This commit is contained in:
parent
3062067446
commit
800acfb6bd
160
dme.py
160
dme.py
@ -1,126 +1,70 @@
|
||||
""" Module to automate message deletion. """
|
||||
from asyncio import sleep
|
||||
from os import path, remove
|
||||
from os.path import exists
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from pagermaid import redis, log, redis_status
|
||||
from pagermaid import log
|
||||
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"),
|
||||
description="编辑并删除当前对话您发送的特定数量的消息。限制:基于消息 ID 的 1000 条消息,大于 1000 "
|
||||
"条可能会触发删除消息过快限制。入群消息非管理员无法删除。(倒序)当数字足够大时即可实现删除所有消息。",
|
||||
parameters="<数量> [文本]")
|
||||
async def dme(context):
|
||||
@listener(is_plugin=False, outgoing=True, command=alias_command("dme"),
|
||||
description=lang('sp_des'),
|
||||
parameters=lang('sp_parameters'))
|
||||
async def selfprune(context):
|
||||
""" Deletes specific amount of messages you sent. """
|
||||
reply = await context.get_reply_message()
|
||||
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
|
||||
msgs = []
|
||||
count_buffer = 0
|
||||
try:
|
||||
async for message in context.client.iter_messages(context.chat_id, from_user="me"):
|
||||
if count_buffer == count:
|
||||
break
|
||||
if message.forward or message.via_bot or message.sticker or message.contact or message.poll or message.game or message.geo:
|
||||
pass
|
||||
elif message.text or message.voice:
|
||||
if not message.text == dme_msg:
|
||||
try:
|
||||
await message.edit(dme_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()
|
||||
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
|
||||
except ValueError:
|
||||
try:
|
||||
await context.edit('出错了呜呜呜 ~ 无法识别的对话')
|
||||
except:
|
||||
pass
|
||||
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
|
||||
count -= 1
|
||||
count_buffer -= 1
|
||||
await log(f"批量删除了自行发送的 {str(count_buffer)} / {str(count)} 条消息。")
|
||||
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)
|
||||
except:
|
||||
return
|
||||
await sleep(.5)
|
||||
await notification.delete()
|
||||
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')
|
||||
)
|
||||
|
||||
|
10
list.json
10
list.json
@ -829,6 +829,16 @@
|
||||
"supported": true,
|
||||
"des-short": "天天疯狂!",
|
||||
"des": "随机输出KFC疯狂星期四文案。\n指令:-crazy4"
|
||||
},
|
||||
{
|
||||
"name": "dme",
|
||||
"version": "1.2",
|
||||
"section": "chat",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "4.3 kb",
|
||||
"supported": true,
|
||||
"des-short": "删除当前对话您发送的特定数量的消息。",
|
||||
"des": "删除当前对话您发送的特定数量的消息。"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user