aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Senjan21 <[email protected]>2021-04-16 13:03:13 +0200
committerGravatar Senjan21 <[email protected]>2021-04-16 13:03:13 +0200
commite5e4343435c31f53e4d58cf8cbd180bfccd94023 (patch)
treed5cb8af03da256457014babf1c47f3ed3f8e4f2e
parentDon't delete invocation in mod channel (diff)
document snowflake check better
-rw-r--r--bot/exts/utils/clean.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/bot/exts/utils/clean.py b/bot/exts/utils/clean.py
index d9164738a..e08be79fe 100644
--- a/bot/exts/utils/clean.py
+++ b/bot/exts/utils/clean.py
@@ -105,6 +105,17 @@ class Clean(Cog):
return message_mappings, message_ids
+ def is_older_than_14d(self, message: Message) -> bool:
+ """
+ Precisely checks if message is older than 14 days, bulk deletion limit.
+
+ Inspired by how purge works internally.
+ Comparison on message age could possibly be less accurate which in turn would resort in problems
+ with message deletion if said messages are very close to the 14d mark.
+ """
+ two_weeks_old_snowflake = int((time.time() - 14 * 24 * 60 * 60) * 1000.0 - 1420070400000) << 22
+ return message.id < two_weeks_old_snowflake
+
async def _clean_messages(
self,
amount: int,
@@ -251,9 +262,6 @@ class Clean(Cog):
# Now let's delete the actual messages with purge.
self.mod_log.ignore(Event.message_delete, *message_ids)
- # Creates ID like int object that would represent an object that is exactly 14 days old
- minimum_time = int((time.time() - 14 * 24 * 60 * 60) * 1000.0 - 1420070400000) << 22
-
for channel, messages in message_mappings.items():
to_delete = []
@@ -264,7 +272,7 @@ class Clean(Cog):
# Means that the cleaning was canceled
return
- if message.id < minimum_time:
+ if self.is_older_than_14d(message):
# further messages are too old to be deleted in bulk
await self._delete_messages_individually(messages[current_index:])
if not self.cleaning: