improve delete.py

This commit is contained in:
blank X 2020-10-17 13:06:03 +07:00
parent e76395bb0d
commit a2bd2dbfc8
1 changed files with 22 additions and 10 deletions

View File

@ -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
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 <i>(as reply to a message)</i> - Deletes the replied to message
'''{prefix}delete <i>(maybe reply to a message)</i> - Deletes the replied to message, or your latest message
Aliases: {prefix}d, {prefix}del
{prefix}purge <i>(as reply to a message)</i> - Purges the messages between the one you replied (and including the one you replied)