From 1bb7b6ff2d9061733505346b9c5ec3e2c47863b0 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 8 Oct 2017 07:52:56 -0400 Subject: [PATCH] [commands] Make CooldownMapping.get_bucket take Message instead. Requiring a full blown Context might be a bit overkill considering we only use a single attribute from it. --- discord/ext/commands/cooldowns.py | 7 +++---- discord/ext/commands/core.py | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/discord/ext/commands/cooldowns.py b/discord/ext/commands/cooldowns.py index 5849e5049..81184e4b1 100644 --- a/discord/ext/commands/cooldowns.py +++ b/discord/ext/commands/cooldowns.py @@ -103,8 +103,7 @@ class CooldownMapping: def from_cooldown(cls, rate, per, type): return cls(Cooldown(rate, per, type)) - def _bucket_key(self, ctx): - msg = ctx.message + def _bucket_key(self, msg): bucket_type = self._cooldown.type if bucket_type is BucketType.user: return msg.author.id @@ -122,12 +121,12 @@ class CooldownMapping: for k in dead_keys: del self._cache[k] - def get_bucket(self, ctx): + def get_bucket(self, message): if self._cooldown.type is BucketType.default: return self._cooldown self._verify_cache_integrity() - key = self._bucket_key(ctx) + key = self._bucket_key(message) if key not in self._cache: bucket = self._cooldown.copy() self._cache[key] = bucket diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 1778ac7f9..c594ec975 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -438,7 +438,7 @@ class Command: yield from self._verify_checks(ctx) if self._buckets.valid: - bucket = self._buckets.get_bucket(ctx) + bucket = self._buckets.get_bucket(ctx.message) retry_after = bucket.update_rate_limit() if retry_after: raise CommandOnCooldown(bucket, retry_after) @@ -462,7 +462,7 @@ class Command: if not self._buckets.valid: return False - bucket = self._buckets.get_bucket(ctx) + bucket = self._buckets.get_bucket(ctx.message) return bucket.get_tokens() == 0 def reset_cooldown(self, ctx): @@ -474,7 +474,7 @@ class Command: The invocation context to reset the cooldown under. """ if self._buckets.valid: - bucket = self._buckets.get_bucket(ctx) + bucket = self._buckets.get_bucket(ctx.message) bucket.reset() @asyncio.coroutine