aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-10-17 22:51:22 -0400
committerRapptz <[email protected]>2020-10-17 22:51:29 -0400
commit2509ca6a822c2a323614bd7f8282870cdf5b52d3 (patch)
tree469dc1329239e1e1c14b226f410b95cd39766836
parentFix attribute errors when timing out during chunking start-up (diff)
downloaddiscord.py-2509ca6a822c2a323614bd7f8282870cdf5b52d3.tar.xz
discord.py-2509ca6a822c2a323614bd7f8282870cdf5b52d3.zip
Add internal method to check if the websocket is currently ratelimited
-rw-r--r--discord/gateway.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index b0354489..ed583495 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -76,6 +76,12 @@ class GatewayRatelimiter:
self.lock = asyncio.Lock()
self.shard_id = None
+ def is_ratelimited(self):
+ current = time.time()
+ if current > self.window + self.per:
+ return False
+ return self.remaining == 0
+
def get_delay(self):
current = time.time()
@@ -287,6 +293,9 @@ class DiscordWebSocket:
def open(self):
return not self.socket.closed
+ def is_ratelimited(self):
+ return self._rate_limiter.is_ratelimited()
+
@classmethod
async def from_client(cls, client, *, initial=False, gateway=None, shard_id=None, session=None, sequence=None, resume=False):
"""Creates a main websocket for Discord from a :class:`Client`.