[Cleanup] Add [p]cleanup spam command #3688
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!3688
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/cleanup"
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
An addition to the cleanup cog. Checks the last 50 messages from the current channel, stores the message along with a reference to the author, and compares them. Deletes the duplicate/spam messages, but keeps a single copy.
Can I suggest you keep the default messages at 50, but allow a number to be specified too. I think that'd be handy. Nice work otherwise!
Great idea. Ask, and you shall receive! Thank you.
Edit 1: Also fixed the counts to consider the message that sent the invoking command.


Edit 2: images, oops forgot them.
Thanks for making this command and contributing it to Red, this is a very cool idea 🙂
I have few things (review comments) for you that I think could be improved.
It would also be great if this command (similarly to other commands) used
get_messages_for_deletion()andcheck_100_plus()methods.I know that
get_messages_for_deletion()doesn't supportlimitkwarg which you need here but it shouldn't be hard to add support for that kwarg.Small note here, while you don't have to use this function, I just think it might be better to reuse what it does rather than duplicate the checks it does in
[p]cleanup spam's code. Let me know if I missed something about it though.If you have any questions, you can find me on Red's discord (Jackenmen#6607).
Instead of using
number + 1for the command to check 50 messages excluding command message, it might be better to usebeforekwarg. This will also make sure that the bot will not include some message that happens to be sent right after the command message but before we the bot actually requests the channel's history.This isn't the safest way to remove spam messages - there can be messages that don't include any content (e.g. attachment-only messages or messages with embeds) and this would result in the bot removing those messages.
There's no good way to compare attachments so unfortunately the best we can do if we want this to be safe is ignore such messages completely. And as for embeds, we could compare them using
embed.to_dict():It might not be obvious to the user using this command that it deletes duplicates but leaves one instance of the message, could you perhaps make it a bit more clear?
Thank you! I really appreciate your comments and made some changes.
For the
check_100_plus(), I included it after checking the history because the message states it'll delete thenumberof messages when the actual number will be less than that.I also setNope. Doesn't work the way I thought.oldest_first=Truefor the history to keep the original message from the author. I've been thinking about the best way to handle it. Keep the earliest or the latest? I went this route. Let me know your opinions on this.Also, currently looking into how
get_messages_for_deletion()would work with this.Looking forward to more feedback. Thanks again!
Looks good to me, but since you said you'll look into switching it to
get_messages_for_deletion()let me know when you do, and do ask if there's anything you need to know.Also I have one more review comment, though it's more of a nitpick.
Putting IDs of involved discord objects can be helpful to bot owners looking at the log so adding them in parentheses should work for that.
Also, I propose using %-formatting as it works better with various logging tooling. While we don't use any, at least currently, some bot users might be.
I actually just made that change! lol
I wanted to keep it with the same style
Okay, so I made the changes and fixed my all dumb mistakes I hope..
Looks good to me, thank you so much for the contribution and I hope it won't be the last ;)
You can expect this feature in next Red release.