PagerMaid_Plugins_Pyro/da/main.py
xtaodada fb5a3f5baf
All checks were successful
Github commit to telegram / build (push) Successful in 13s
♻️ Reformat All Plugins
2024-09-28 22:35:08 +08:00

40 lines
1.4 KiB
Python

import contextlib
from pagermaid.dependence import add_delete_message_job
from pagermaid.enums import Client, Message
from pagermaid.listener import listener
from pagermaid.utils import alias_command
from pagermaid.utils.bot_utils import log
@listener(
command="da",
groups_only=True,
need_admin=True,
description="删除群内所有消息。(非群组管理员只删除自己的消息)",
parameters="[true]",
)
async def da(bot: Client, message: Message):
if message.arguments != "true":
return await message.edit(
f"[da] 呜呜呜,请执行 `,{alias_command('da')} true` 来删除所有消息。"
)
await message.edit("[da] 正在删除所有消息 . . .")
messages = []
count = 0
async for message in bot.get_chat_history(message.chat.id):
messages.append(message.id)
count += 1
if count % 100 == 0:
with contextlib.suppress(Exception):
await bot.delete_messages(message.chat.id, messages)
messages = []
if messages:
with contextlib.suppress(Exception):
await bot.delete_messages(message.chat.id, messages)
await log(f"批量删除了 {str(count)} 条消息。")
with contextlib.suppress(Exception):
reply = await bot.send_message(message.chat.id, f"批量删除了 {str(count)} 条消息。")
add_delete_message_job(reply, delete_seconds=5)