2020-08-11 14:24:26 +00:00
|
|
|
""" Module to automate message deletion. """
|
|
|
|
from asyncio import sleep
|
2022-01-16 12:35:14 +00:00
|
|
|
from pagermaid import log
|
2020-08-11 14:24:26 +00:00
|
|
|
from pagermaid.listener import listener
|
2022-01-16 12:35:14 +00:00
|
|
|
from pagermaid.utils import alias_command, lang
|
2020-08-11 14:24:26 +00:00
|
|
|
|
|
|
|
|
2022-01-16 12:35:14 +00:00
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command("dme"),
|
|
|
|
description=lang('sp_des'),
|
|
|
|
parameters=lang('sp_parameters'))
|
|
|
|
async def selfprune(context):
|
2020-08-11 14:24:26 +00:00
|
|
|
""" Deletes specific amount of messages you sent. """
|
2022-01-16 12:35:14 +00:00
|
|
|
msgs = []
|
|
|
|
count_buffer = 0
|
|
|
|
if not len(context.parameter) == 1:
|
|
|
|
if not context.reply_to_msg_id:
|
|
|
|
await context.edit(lang('arg_error'))
|
2021-07-02 12:04:08 +00:00
|
|
|
return
|
2022-01-16 12:35:14 +00:00
|
|
|
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
|
|
|
|
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()
|
2020-08-11 14:24:26 +00:00
|
|
|
return
|
2021-08-21 11:35:00 +00:00
|
|
|
try:
|
2022-01-16 12:35:14 +00:00
|
|
|
count = int(context.parameter[0])
|
|
|
|
await context.delete()
|
2021-08-21 11:35:00 +00:00
|
|
|
except ValueError:
|
2022-01-16 12:35:14 +00:00
|
|
|
await context.edit(lang('arg_error'))
|
2021-08-21 11:35:00 +00:00
|
|
|
return
|
2022-01-16 12:35:14 +00:00
|
|
|
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')}")
|
2021-08-21 11:35:00 +00:00
|
|
|
try:
|
|
|
|
notification = await send_prune_notify(context, count_buffer, count)
|
2022-01-16 12:35:14 +00:00
|
|
|
await sleep(1)
|
|
|
|
await notification.delete()
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2020-08-11 14:24:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def send_prune_notify(context, count_buffer, count):
|
|
|
|
return await context.client.send_message(
|
|
|
|
context.chat_id,
|
2022-01-16 12:35:14 +00:00
|
|
|
lang('spn_deleted')
|
2020-08-11 14:24:26 +00:00
|
|
|
+ str(count_buffer) + " / " + str(count)
|
2022-01-16 12:35:14 +00:00
|
|
|
+ lang('prune_hint2')
|
2020-08-11 14:24:26 +00:00
|
|
|
)
|