[commands] Provide a way to retrieve time left for a cooldown

This commit is contained in:
Dan Hess
2020-08-05 20:37:08 -05:00
committed by GitHub
parent 09f432016c
commit 3a9fd00a1a
2 changed files with 34 additions and 1 deletions

View File

@ -91,6 +91,15 @@ class Cooldown:
tokens = self.rate
return tokens
def get_retry_after(self, current=None):
current = current or time.time()
tokens = self.get_tokens(current)
if tokens == 0:
return self.per - (current - self._window)
return 0.0
def update_rate_limit(self, current=None):
current = current or time.time()
self._last = current