2020-08-24 07:55:33 +00:00
|
|
|
from asyncio import sleep
|
2022-01-18 08:47:20 +00:00
|
|
|
from pagermaid import log, version
|
2020-08-24 07:55:33 +00:00
|
|
|
from pagermaid.listener import listener
|
2021-06-16 07:09:40 +00:00
|
|
|
from pagermaid.utils import alias_command
|
2021-08-16 14:32:42 +00:00
|
|
|
from telethon.errors import PeerFloodError
|
2020-08-24 07:55:33 +00:00
|
|
|
|
2021-06-16 07:09:40 +00:00
|
|
|
|
|
|
|
@listener(is_plugin=True, outgoing=True, command=alias_command("da"),
|
2020-08-24 07:55:33 +00:00
|
|
|
description="以此命令删除所有消息。(非群组管理员只删除自己的消息)",
|
|
|
|
parameters="<text>")
|
2021-06-16 07:09:40 +00:00
|
|
|
async def da(context):
|
2020-08-24 07:55:33 +00:00
|
|
|
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)} 条消息。")
|
2021-08-16 14:32:42 +00:00
|
|
|
try:
|
|
|
|
notification = await send_prune_notify(context, count)
|
2021-09-03 07:33:59 +00:00
|
|
|
except:
|
|
|
|
return
|
2020-08-24 07:55:33 +00:00
|
|
|
await sleep(.5)
|
|
|
|
await notification.delete()
|
|
|
|
|
2021-06-16 07:09:40 +00:00
|
|
|
|
2020-08-24 07:55:33 +00:00
|
|
|
async def send_prune_notify(context, count):
|
|
|
|
return await context.client.send_message(
|
|
|
|
context.chat_id,
|
|
|
|
"批量删除了 "
|
|
|
|
+ str(count)
|
|
|
|
+ " 条消息。"
|
|
|
|
)
|