From a2bd2dbfc8729b194a936ee3030f404804cd785a Mon Sep 17 00:00:00 2001 From: blank X Date: Sat, 17 Oct 2020 13:06:03 +0700 Subject: [PATCH] improve delete.py --- sukuinote/plugins/delete.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sukuinote/plugins/delete.py b/sukuinote/plugins/delete.py index d93278a..18017f5 100644 --- a/sukuinote/plugins/delete.py +++ b/sukuinote/plugins/delete.py @@ -10,20 +10,28 @@ async def delete(client, message): reply = message.reply_to_message if not getattr(reply, 'empty', True): messages.add(reply.message_id) + else: + async for i in client.search_messages(message.chat.id, offset=1, limit=1, from_user='me'): + messages.add(i.message_id) await client.delete_messages(message.chat.id, messages) @Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['p', 'purge', 'sp', 'selfpurge'], prefixes=config['config']['prefixes'])) @log_errors @public_log_errors async def purge(client, message): - selfpurge = 's' in message.command[0] + command = message.command + selfpurge = 'me' if 's' in message.command.pop(0) else None + command = ' '.join(command) ids = set((message.message_id,)) reply = message.reply_to_message - if not getattr(reply, 'empty', True): - for i in await client.get_messages(message.chat.id, range(reply.message_id, message.message_id), replies=0): - if selfpurge and not i.outgoing: - continue + if command.isnumeric(): + async for i in client.search_messages(message.chat.id, limit=int(command), offset=1, from_user=selfpurge): + ids.add(i,message_id) + elif not getattr(reply, 'empty', True): + async for i in client.search_messages(message.chat.id, offset=1, from_user=selfpurge): ids.add(i.message_id) + if reply.message_id >= i.message_id: + break await client.delete_messages(message.chat.id, ids) yeetpurge_info = {True: dict(), False: dict()} @@ -42,14 +50,18 @@ async def yeetpurge(client, message): return og_message, og_resp, og_reply = info.pop(message.chat.id) messages = set((og_message, og_resp, message.message_id)) - for i in await client.get_messages(message.chat.id, range(og_reply, reply.message_id + 1), replies=0): - if 's' in message.command[0] and not i.outgoing: - continue - messages.add(i.message_id) + thing = [og_reply, reply.message_id] + thing.sort() + thing0, thing1 = thing + async for i in client.iter_history(message.chat.id, offset_id=thing1): + if not ('s' in message.command[0] and not i.outgoing): + messages.add(i.message_id) + if thing0 >= i.message_id: + break await client.delete_messages(message.chat.id, messages) help_dict['delete'] = ('Delete', -'''{prefix}delete (as reply to a message) - Deletes the replied to message +'''{prefix}delete (maybe reply to a message) - Deletes the replied to message, or your latest message Aliases: {prefix}d, {prefix}del {prefix}purge (as reply to a message) - Purges the messages between the one you replied (and including the one you replied)