[commands] Added a method to reset command cooldown.
This commit is contained in:
parent
a23e51f6c4
commit
b7ffbca0c7
@ -43,6 +43,7 @@ class Cooldown:
|
|||||||
self.type = type
|
self.type = type
|
||||||
self._window = 0.0
|
self._window = 0.0
|
||||||
self._tokens = self.rate
|
self._tokens = self.rate
|
||||||
|
self._last = 0.0
|
||||||
|
|
||||||
if not isinstance(self.type, BucketType):
|
if not isinstance(self.type, BucketType):
|
||||||
raise TypeError('Cooldown type must be a BucketType')
|
raise TypeError('Cooldown type must be a BucketType')
|
||||||
@ -72,6 +73,10 @@ class Cooldown:
|
|||||||
if self._tokens == 0:
|
if self._tokens == 0:
|
||||||
self._window = current
|
self._window = current
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self._tokens = self.rate
|
||||||
|
self._last = 0.0
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return Cooldown(self.rate, self.per, self.type)
|
return Cooldown(self.rate, self.per, self.type)
|
||||||
|
|
||||||
|
@ -337,6 +337,18 @@ class Command:
|
|||||||
if retry_after:
|
if retry_after:
|
||||||
raise CommandOnCooldown(bucket, retry_after)
|
raise CommandOnCooldown(bucket, retry_after)
|
||||||
|
|
||||||
|
def reset_cooldown(self, ctx):
|
||||||
|
"""Resets the cooldown on this command.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-----------
|
||||||
|
ctx: :class:`Context`
|
||||||
|
The invocation context to reset the cooldown under.
|
||||||
|
"""
|
||||||
|
if self._buckets.valid:
|
||||||
|
bucket = self._buckets.get_bucket(ctx)
|
||||||
|
bucket.reset()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def invoke(self, ctx):
|
def invoke(self, ctx):
|
||||||
ctx.command = self
|
ctx.command = self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user