[V3 Cleanup] Refactor get_messages_for_deletion #1980
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!1980
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-13"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
This begins a more long-term fix. Part of that is changing a function signature, and as such, steps are being taken to do this with a proper warning for 3rd party devs using this utility function.
This is targeting beta 20, but promises changes in beta 21, and beta 22
PRs will be opened and connected to this.
I've tried this change on a couple bots with no change in the bot's response, cleanup after still returns 0 messages deleted.
This has been further changed to not break early, and filter the resultant list:
From the discord.py documentation:
This also (potentially) explains the previously inconsistent behavior. We couldn't use
reverse=Truewith the previous loop strategy and an early break, andreverse=Falsebreaking on a message date isn't safe due to this either.This fixes
[p]cleanup afterbut breaks all other cleanup commands.You've also refactored
get_messages_for_deletionwhich changes a lot of the behaviour unexpectedly. For example, the idea is to deletenumberof messages, whereaslimitis the amount of messages to be collected at a time (confusing but we're just fixing one command here, we're not rewriting a cog)Why not just not use
get_messages_for_deletionin this command? Just get all messages after the given message (as long as the message is less than 14 days ago), remove pinned ones (if requested), anddelete_messages. Otherwise this helper method is just getting too messy and complicated.Given that this PR is fixing a currently obselete command, I will merge it into beta 19 post-cutoff (we already are post-cutoff) as long as it doesn't affect the behaviour of the rest of the cog.
This shouldn't break any other cleanup command and the fact that it did was a fault of me not handling a specific issue with it. This should be fixed in this method, as it was made a static method specifically so that other things can use it too, we don't need to make a special casing for this, just need to handle it correctly.
@ -68,35 +72,55 @@ class Cleanup:- The message is less than 14 days oldI'd rather use
ctx.message.created_atand do slightly less than 14 days (like 13 days, 23 hours and 55 minutes), since the system time could be out of sync with discord's,created_atshould be correct since it uses the snowflake to calculate the time.Because it's a timedelta, being out of sync on the base time isnt a
concern, and I'd prefer removing ctx as we don't need it, so it opens up
for event based usage without mocking an object.
I agree making it slightly under 14 days makes sense.
On Mon, Aug 13, 2018, 2:16 AM Toby Harradine notifications@github.com
wrote:
Closing favoring #2013
Pull request closed