improve delete.py
This commit is contained in:
parent
e76395bb0d
commit
a2bd2dbfc8
|
@ -10,20 +10,28 @@ async def delete(client, message):
|
||||||
reply = message.reply_to_message
|
reply = message.reply_to_message
|
||||||
if not getattr(reply, 'empty', True):
|
if not getattr(reply, 'empty', True):
|
||||||
messages.add(reply.message_id)
|
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)
|
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']))
|
@Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['p', 'purge', 'sp', 'selfpurge'], prefixes=config['config']['prefixes']))
|
||||||
@log_errors
|
@log_errors
|
||||||
@public_log_errors
|
@public_log_errors
|
||||||
async def purge(client, message):
|
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,))
|
ids = set((message.message_id,))
|
||||||
reply = message.reply_to_message
|
reply = message.reply_to_message
|
||||||
if not getattr(reply, 'empty', True):
|
if command.isnumeric():
|
||||||
for i in await client.get_messages(message.chat.id, range(reply.message_id, message.message_id), replies=0):
|
async for i in client.search_messages(message.chat.id, limit=int(command), offset=1, from_user=selfpurge):
|
||||||
if selfpurge and not i.outgoing:
|
ids.add(i,message_id)
|
||||||
continue
|
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)
|
ids.add(i.message_id)
|
||||||
|
if reply.message_id >= i.message_id:
|
||||||
|
break
|
||||||
await client.delete_messages(message.chat.id, ids)
|
await client.delete_messages(message.chat.id, ids)
|
||||||
|
|
||||||
yeetpurge_info = {True: dict(), False: dict()}
|
yeetpurge_info = {True: dict(), False: dict()}
|
||||||
|
@ -42,14 +50,18 @@ async def yeetpurge(client, message):
|
||||||
return
|
return
|
||||||
og_message, og_resp, og_reply = info.pop(message.chat.id)
|
og_message, og_resp, og_reply = info.pop(message.chat.id)
|
||||||
messages = set((og_message, og_resp, message.message_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):
|
thing = [og_reply, reply.message_id]
|
||||||
if 's' in message.command[0] and not i.outgoing:
|
thing.sort()
|
||||||
continue
|
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)
|
messages.add(i.message_id)
|
||||||
|
if thing0 >= i.message_id:
|
||||||
|
break
|
||||||
await client.delete_messages(message.chat.id, messages)
|
await client.delete_messages(message.chat.id, messages)
|
||||||
|
|
||||||
help_dict['delete'] = ('Delete',
|
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
|
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)
|
{prefix}purge <i>(as reply to a message)</i> - Purges the messages between the one you replied (and including the one you replied)
|
||||||
|
|
Loading…
Reference in New Issue