2021-07-28 09:53:59 +00:00
|
|
|
""" Module to automate sticker deletion. """
|
2022-01-18 08:47:20 +00:00
|
|
|
from pagermaid import log, version
|
2021-07-28 09:53:59 +00:00
|
|
|
from pagermaid.listener import listener
|
|
|
|
from pagermaid.utils import alias_command, lang
|
|
|
|
|
|
|
|
|
|
|
|
@listener(is_plugin=True, outgoing=True, command=alias_command("fuckmessage"),
|
|
|
|
description="删除最近 200 条消息中包含指定关键字的消息。",
|
|
|
|
parameters="<关键词>")
|
|
|
|
async def fuck_message(context):
|
|
|
|
""" Deletes specific amount of messages in chat. """
|
|
|
|
if not context.arguments:
|
|
|
|
await context.edit(lang('arg_error'))
|
|
|
|
return
|
|
|
|
input_chat = await context.get_input_chat()
|
|
|
|
count_buffer = 0
|
|
|
|
count = 0
|
|
|
|
messages = []
|
|
|
|
async for message in context.client.iter_messages(context.chat_id):
|
|
|
|
if count_buffer == 200:
|
|
|
|
break
|
2021-07-28 12:47:21 +00:00
|
|
|
if message.text:
|
|
|
|
if context.arguments in message.text:
|
|
|
|
messages.append(message)
|
|
|
|
count += 1
|
2021-07-28 09:53:59 +00:00
|
|
|
if len(messages) > 50:
|
|
|
|
try:
|
|
|
|
await context.client.delete_messages(input_chat, messages)
|
|
|
|
except Exception as e:
|
|
|
|
await log(f'插件 fuckmessage 发生错误:\n{e}')
|
|
|
|
count_buffer += 1
|
|
|
|
text = f"删除了 {count} / {count_buffer} 条 消息 。"
|
|
|
|
try:
|
|
|
|
await context.client.delete_messages(input_chat, messages)
|
|
|
|
except Exception as e:
|
|
|
|
await log(f'插件 fuckmessage 发生错误:\n{e}')
|
|
|
|
await log(text)
|