mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-07 02:21:54 +00:00
[commands] Fix errors when DynamicCooldown returns None
This commit is contained in:
parent
dbb00bd361
commit
2be65e5874
@ -125,9 +125,9 @@ class CooldownMapping:
|
|||||||
def create_bucket(self, message: Message) -> Cooldown:
|
def create_bucket(self, message: Message) -> Cooldown:
|
||||||
return self._cooldown.copy() # type: ignore
|
return self._cooldown.copy() # type: ignore
|
||||||
|
|
||||||
def get_bucket(self, message: Message, current: Optional[float] = None) -> Cooldown:
|
def get_bucket(self, message: Message, current: Optional[float] = None) -> Optional[Cooldown]:
|
||||||
if self._type is BucketType.default:
|
if self._type is BucketType.default:
|
||||||
return self._cooldown # type: ignore
|
return self._cooldown
|
||||||
|
|
||||||
self._verify_cache_integrity(current)
|
self._verify_cache_integrity(current)
|
||||||
key = self._bucket_key(message)
|
key = self._bucket_key(message)
|
||||||
@ -142,6 +142,8 @@ class CooldownMapping:
|
|||||||
|
|
||||||
def update_rate_limit(self, message: Message, current: Optional[float] = None, tokens: int = 1) -> Optional[float]:
|
def update_rate_limit(self, message: Message, current: Optional[float] = None, tokens: int = 1) -> Optional[float]:
|
||||||
bucket = self.get_bucket(message, current)
|
bucket = self.get_bucket(message, current)
|
||||||
|
if bucket is None:
|
||||||
|
return None
|
||||||
return bucket.update_rate_limit(current, tokens=tokens)
|
return bucket.update_rate_limit(current, tokens=tokens)
|
||||||
|
|
||||||
|
|
||||||
|
@ -930,6 +930,8 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
bucket = self._buckets.get_bucket(ctx.message)
|
bucket = self._buckets.get_bucket(ctx.message)
|
||||||
|
if bucket is None:
|
||||||
|
return False
|
||||||
dt = ctx.message.edited_at or ctx.message.created_at
|
dt = ctx.message.edited_at or ctx.message.created_at
|
||||||
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
|
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||||
return bucket.get_tokens(current) == 0
|
return bucket.get_tokens(current) == 0
|
||||||
@ -948,6 +950,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
"""
|
"""
|
||||||
if self._buckets.valid:
|
if self._buckets.valid:
|
||||||
bucket = self._buckets.get_bucket(ctx.message)
|
bucket = self._buckets.get_bucket(ctx.message)
|
||||||
|
if bucket is not None:
|
||||||
bucket.reset()
|
bucket.reset()
|
||||||
|
|
||||||
def get_cooldown_retry_after(self, ctx: Context[BotT], /) -> float:
|
def get_cooldown_retry_after(self, ctx: Context[BotT], /) -> float:
|
||||||
@ -972,6 +975,8 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
"""
|
"""
|
||||||
if self._buckets.valid:
|
if self._buckets.valid:
|
||||||
bucket = self._buckets.get_bucket(ctx.message)
|
bucket = self._buckets.get_bucket(ctx.message)
|
||||||
|
if bucket is None:
|
||||||
|
return 0.0
|
||||||
dt = ctx.message.edited_at or ctx.message.created_at
|
dt = ctx.message.edited_at or ctx.message.created_at
|
||||||
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
|
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||||
return bucket.get_retry_after(current)
|
return bucket.get_retry_after(current)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user