From 2509ca6a822c2a323614bd7f8282870cdf5b52d3 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 17 Oct 2020 22:51:22 -0400 Subject: [PATCH] Add internal method to check if the websocket is currently ratelimited --- discord/gateway.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/discord/gateway.py b/discord/gateway.py index b03544893..ed583495a 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`.