[Cleanup] Add [p]cleanup spam command #3688

Merged
idle-user merged 14 commits from feature/cleanup into V3/develop 2020-03-26 22:32:11 +01:00
idle-user commented 2020-03-24 17:03:41 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

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.

image

image

### Type - [ ] Bugfix - [ ] Enhancement - [x] New feature ### 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. ![image](https://user-images.githubusercontent.com/15640986/77448198-b748e900-6dad-11ea-9e3f-7b1d62ea5636.png) ![image](https://user-images.githubusercontent.com/15640986/77448220-bca63380-6dad-11ea-89c9-9f1fdc35dd93.png)
palmtree5 (Migrated from github.com) reviewed 2020-03-24 17:03:41 +01:00
MeatyChunks commented 2020-03-25 00:49:24 +01:00 (Migrated from github.com)

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!

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!
idle-user commented 2020-03-25 01:55:46 +01:00 (Migrated from github.com)

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.
image
image

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. ![image](https://user-images.githubusercontent.com/15640986/77490784-226bdd00-6df9-11ea-9bbc-02b24b23fbb1.png) ![image](https://user-images.githubusercontent.com/15640986/77490787-24ce3700-6df9-11ea-91da-0c18329c7c47.png)
Jackenmen (Migrated from github.com) requested changes 2020-03-26 12:56:03 +01:00
Jackenmen (Migrated from github.com) left a comment

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() and check_100_plus() methods.
I know that get_messages_for_deletion() doesn't support limit kwarg 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).

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()` and `check_100_plus()` methods. I know that `get_messages_for_deletion()` doesn't support `limit` kwarg 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](discord.gg/red) (Jackenmen#6607).
Jackenmen (Migrated from github.com) commented 2020-03-26 11:55:18 +01:00

Instead of using number + 1 for the command to check 50 messages excluding command message, it might be better to use before kwarg. 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.

        async for msg in ctx.channel.history(limit=number, before=ctx.message):
Instead of using `number + 1` for the command to check 50 messages excluding command message, it might be better to use `before` kwarg. 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. ```suggestion async for msg in ctx.channel.history(limit=number, before=ctx.message): ```
Jackenmen (Migrated from github.com) commented 2020-03-26 12:27:02 +01:00

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():

            if msg.attachments:
                continue
            c = (msg.author.id, msg.content, [e.to_dict() for e in msg.embeds])
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()`: ```suggestion if msg.attachments: continue c = (msg.author.id, msg.content, [e.to_dict() for e in msg.embeds]) ```
Jackenmen (Migrated from github.com) commented 2020-03-26 12:29:50 +01:00

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?

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?
idle-user commented 2020-03-26 17:29:41 +01:00 (Migrated from github.com)

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 the number of messages when the actual number will be less than that.

I also set oldest_first=True for 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. Nope. Doesn't work the way I thought.

Also, currently looking into how get_messages_for_deletion() would work with this.
Looking forward to more feedback. Thanks again!

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 the `number` of messages when the actual number will be less than that. ~~I also set `oldest_first=True` for 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.~~ Nope. Doesn't work the way I thought. Also, currently looking into how `get_messages_for_deletion()` would work with this. Looking forward to more feedback. Thanks again!
Jackenmen (Migrated from github.com) reviewed 2020-03-26 17:55:45 +01:00
Jackenmen (Migrated from github.com) left a comment

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.

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.
Jackenmen (Migrated from github.com) commented 2020-03-26 17:39:48 +01:00

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.

            "%s (%s) deleted %s spam messages in channel %s (%s).",
            ctx.author,
            ctx.author.id,
            len(spam) - 1,
            channel,
            channel.id,
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. ```suggestion "%s (%s) deleted %s spam messages in channel %s (%s).", ctx.author, ctx.author.id, len(spam) - 1, channel, channel.id, ```
idle-user (Migrated from github.com) reviewed 2020-03-26 17:56:25 +01:00
idle-user (Migrated from github.com) commented 2020-03-26 17:56:25 +01:00

I actually just made that change! lol
I wanted to keep it with the same style

I actually just made that change! lol I wanted to keep it with the same style
idle-user commented 2020-03-26 20:15:46 +01:00 (Migrated from github.com)

Okay, so I made the changes and fixed my all dumb mistakes I hope..

Okay, so I made the changes and fixed my all dumb mistakes I hope..
Jackenmen (Migrated from github.com) approved these changes 2020-03-26 21:56:05 +01:00
Jackenmen (Migrated from github.com) left a comment

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.

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.
Sign in to join this conversation.
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 milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!3688
No description provided.