diff options
author | 2020-05-31 15:27:53 -0700 | |
---|---|---|
committer | 2020-05-31 15:27:53 -0700 | |
commit | 196ce8a828a0fed7450cad1ee0bba25ef608214a (patch) | |
tree | 376805cdda3761cd25b263e1dc1f5cd5c83c59d2 | |
parent | Revert message ignore approach. (diff) |
Use the messages returned by `purge` to upload message logs
This ensures that only what was actually deleted will be uploaded.
I managed to get a 400 response from our API when purging twice in
quick succession. Searching the history manually for these messages is
unreliable cause of some sort of race condition.
-rw-r--r-- | bot/cogs/clean.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/bot/cogs/clean.py b/bot/cogs/clean.py index b164cf232..368d91c85 100644 --- a/bot/cogs/clean.py +++ b/bot/cogs/clean.py @@ -117,11 +117,11 @@ class Clean(Cog): self.mod_log.ignore(Event.message_delete, ctx.message.id) await ctx.message.delete() - # Look through the history and retrieve message data messages = [] message_ids = [] self.cleaning = True + # Find the IDs of the messages to delete. IDs are needed in order to ignore mod log events. for channel in channels: async for message in channel.history(limit=amount): @@ -132,21 +132,17 @@ class Clean(Cog): # If the message passes predicate, let's save it. if predicate is None or predicate(message): message_ids.append(message.id) - messages.append(message) self.cleaning = False # Now let's delete the actual messages with purge. self.mod_log.ignore(Event.message_delete, *message_ids) for channel in channels: - await channel.purge( - limit=amount, - check=predicate - ) + messages += await channel.purge(limit=amount, check=predicate) # Reverse the list to restore chronological order if messages: - messages = list(reversed(messages)) + messages = reversed(messages) log_url = await self.mod_log.upload_log(messages, ctx.author.id) else: # Can't build an embed, nothing to clean! |