From d73ad3115fd4e587e586cc7d429512d8ae706931 Mon Sep 17 00:00:00 2001 From: Michael H Date: Tue, 28 Jul 2020 20:39:37 -0400 Subject: [PATCH] Prevent LicenseInfo command from being a source of user command spam (#4110) * Prevent LicenseInfo command from being a source of user command spam * add dep-warn explaining whats needed for this * name issues * Tests... * An empty commit unbroke some of it, but still style issues --- redbot/core/core_commands.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 8878e2c4d..4cae03451 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -2749,6 +2749,21 @@ class Core(commands.Cog, CoreLogic): return msg +# DEP-WARN: CooldownMapping should have a method `from_cooldown` +# which accepts (number, number, bucket) +# the bucket should only be used for the method `_bucket_key` +# and `_bucket_key` should be used to determine the grouping +# of ratelimit consumption. +class LicenseCooldownMapping(commands.CooldownMapping): + """ + This is so that a single user can't spam a channel with this + it's used below as 1 per 3 minutes per user-channel combination. + """ + + def _bucket_key(self, msg): + return (msg.channel.id, msg.author.id) + + # Removing this command from forks is a violation of the GPLv3 under which it is licensed. # Otherwise interfering with the ability for this command to be accessible is also a violation. @commands.command( @@ -2770,3 +2785,9 @@ async def license_info_command(ctx): ) await ctx.send(message) # We need a link which contains a thank you to other projects which we use at some point. + + +# DEP-WARN: command objects should store a single cooldown mapping as `._buckets` +license_info_command._buckets = LicenseCooldownMapping.from_cooldown( + 1, 180, commands.BucketType.member # pick a random bucket,it wont get used. +)