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
This commit is contained in:
Michael H 2020-07-28 20:39:37 -04:00 committed by GitHub
parent 832bdfde22
commit d73ad3115f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2749,6 +2749,21 @@ class Core(commands.Cog, CoreLogic):
return msg 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. # 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. # Otherwise interfering with the ability for this command to be accessible is also a violation.
@commands.command( @commands.command(
@ -2770,3 +2785,9 @@ async def license_info_command(ctx):
) )
await ctx.send(message) await ctx.send(message)
# We need a link which contains a thank you to other projects which we use at some point. # 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.
)