From b6abe9cbb2e63f562bb44e14d51ea87f19da32ac Mon Sep 17 00:00:00 2001 From: Senjan21 <53477086+Senjan21@users.noreply.github.com> Date: Thu, 16 Jul 2020 10:41:54 +0200 Subject: Prevent deleting messages above the desired message. --- bot/cogs/clean.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bot/cogs/clean.py b/bot/cogs/clean.py index aee7fa055..f436e531a 100644 --- a/bot/cogs/clean.py +++ b/bot/cogs/clean.py @@ -132,17 +132,18 @@ class Clean(Cog): # If we are looking for specific message. if until_message: - # Since we will be using `delete_messages` method of a TextChannel and we need message objects to - # use it as well as to send logs we will start appending messages here instead adding them from - # purge. - messages.append(message) + # we could use ID's here however in case if the message we are looking for gets deleted, # we won't have a way to figure that out thus checking for datetime should be more reliable - if message.created_at <= until_message.created_at: + if message.created_at < until_message.created_at: # means we have found the message until which we were supposed to be deleting. - message_ids.append(message.id) break + # Since we will be using `delete_messages` method of a TextChannel and we need message objects to + # use it as well as to send logs we will start appending messages here instead adding them from + # purge. + messages.append(message) + # If the message passes predicate, let's save it. if predicate is None or predicate(message): message_ids.append(message.id) -- cgit v1.2.3