Browse Source

Add internal method to check if the websocket is currently ratelimited

v1.5.x
Rapptz 5 years ago
parent
commit
2509ca6a82
  1. 9
      discord/gateway.py

9
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`.

Loading…
Cancel
Save