Making DeleteRepeats having a custom value per channel #5607
No reviewers
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 milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5607
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/develop"
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?
Resolves #4721
Description of the changes
I added the functionality to custom the number of allowed repeated messages before deleting it per channel.
The most important change of this feature is that the cache went from a map mapping the last messages from the author in the entire guild to a map mapping the messages of the authors per channel.
I also added in the utils file a method to create a new cache with taking into account the custom values per channel.
Have the changes in this PR been tested?
No, no tests have been added to the test files but the behaviour of the new implementation have been tested with scenario tests (and the tox tests still pass).
This is not a complete review. The current implementation of the cache requires too many changes for the rest of the code to be effectively reviewed. I suggest you re-read Jack's comment on the original issue and ensure that you are following his advice in addition to reviewing the comments I have made.
@ -19,21 +19,20 @@ class Events(MixinMeta):"""The old cache only made config calls when it had not already been filled with data for a particular guild. Yours (inefficiently) does so on every message that is checked. You need to only call from config when needed.
You should not be leaving any
printstatements in the code. If there is something that should be displayed in console, you can use theloggingmodule to do so like other parts of the code. This is not such a case however, so these lines should be removed.This is not a fault of your PR, but while you are touching this function it is more efficient if this is the first thing checked instead of it being here.
I honestly cannot tell if it's safe to do this with all the different conditions for how
guild_cachecan be set up and how this line can be reached.This should be part of the
channelscope, not a dict in theguildsettings.The argument to specify the setting should only apply for a channel should be an optional
discord.TextChannel(or perhaps a greedy one if we want to support passing multiple channels?). It should not be a string, and it should not lock the user into only picking the current channel.See above comment about
print.@ -11,3 +13,21 @@ async def is_allowed_by_hierarchy(return TrueSee above comment about
print.@ -19,21 +19,20 @@ class Events(MixinMeta):"""Could I have some more informations about this? Because I didn't change much about this part of the code except for the dict because I needed a dictionary per channel.
@ -19,21 +19,20 @@ class Events(MixinMeta):"""[Your PR code]
github.com/Cog-Creators/Red-DiscordBot@fe92cd88a2/redbot/cogs/mod/utils.py (L20-L24)guild_cachemay be adefaultdict[defaultdict[int]], though it is not guaranteed to be one. Thus, I can't tell if blindly accessingguild_cache[str(channel.id)][author]is safe to do from reading the code. This kind of complexity is a bad code smell, so the way this var is created and used should be rewritten to be clearer.[Current code]
github.com/Cog-Creators/Red-DiscordBot@be00a59ab3/redbot/cogs/mod/events.py (L24-L29)Notice that current code clearly checks whether the guild cache exists, and if it doesn't it clearly creates it, guaranteeing that after the
ifis doneguild_cachewill be adefaultdict[int]. I do not have the same confidence reading the code in this PR.@ -19,21 +19,20 @@ class Events(MixinMeta):"""Ok I understand and I already made the changes. It is possible to create a deque with maxlen = 0. Thus these checks aren't useful anymore and have been deleted
@ -19,21 +19,20 @@ class Events(MixinMeta):"""Letting you know just in case, you have not pushed any changes to this PR since my review. If you're still working, and you mean that you made the changes locally, that's fine. I just can't see any changes so I can only base what I say on what I can see.
@ -19,21 +19,20 @@ class Events(MixinMeta):"""Sorry for the misunderstanding, yes I changed it locally I still have to update my code with these reviews but I will push it in a few days
This PR is looking a lot better than the first time I reviewed it. Still has quite a few things that need to be revised, but I can see it coming together now.
Since this string now has a non-determinant length due to this loop, the eventual
sendof this command should be modified to ensure the resulting message is under 2000 characters, and to properly pagify the message if it is not.If you aren't setting multiple different variables, there is no reason to use this syntax.
@ -305,0 +329,4 @@else:success.add(channel)if len(fails) > 0:As I suggested in my previous review, it is far easier to just type hint the
channelsargument so dpy automatically converts it than to attempt to process it after the fact.@ -308,2 +340,2 @@self.cache.pop(guild.id, None) # remove cache with old repeat limitsawait ctx.send(_("Repeated messages will be ignored."))if len(channels) != 0:channels_string = ""I don't think this is perfect, but it's at least a bit more descriptive than what is currently there.
@ -310,0 +341,4 @@channels_string = ""for channel in success:channels_string += _("{name}, ").format(name=channel.name)await self.config.channel(channel).delete_repeats.set(repeats)This line should not be here, I assume this is left over from your local debugging.
@ -322,0 +366,4 @@else:await self.config.guild(guild).delete_repeats.set(repeats)await ctx.send(This entire block is not needed if you use the converter,
@ -322,0 +381,4 @@# reset the cache for this channelself.cache[guild.id].pop(channel.id, None)else:await ctx.send(You were only updating the cache for the last guild currently, since it was setting outside the loop.
Translation strings (
_("Text to translate here")) should only be used on hardcoded strings or strings with.formatapplied outside of the_(), not on strings that are concatenated from multiple variables, and can thus be dynamic at runtime (IE_(msg + channels_string + ")")should not be a translated string).Note that I kept
successas the variable to loop over, this variable will need to be changed tochannelsin all places you're using it once you change the parameter to convert to channels automatically. I just don't want to add suggestions to every usage of it, since there's quite a few :P@ -360,3 +426,3 @@)@modset.group()@modset.command()You don't have any output in this branch.
I'm not certain, but this file might be part of the public API, and if so these functions should either not be in this file or be private.
It's been over 3 years since the last changes on this PR were made, and there are still unresolved review comments on this PR. It's time to just close this and let someone else pick it up.
Pull request closed