Browse Source

Adding "latency" var to GatewayClient (#168)

* Local Fixes & Client UserUpdate Gateway Event

- Changed 'READ_MESSAGES' to 'VIEW_CHANNEL' to keep with Discord's API Docs
- Defaulted Guild.premium_subscription_count to 0 to stop error
- max_presences to 5,000 as Discord's API Suggest
- Added UserUpdate event for when the Client user is updated.

* Flake8 Spacing

* Update state.py

* Adding latency checking

*Note: Latency is in seconds NOT ms*

* Update client.py
staging/v1.0.0
Justin 5 years ago
committed by Andrei Zbikowski
parent
commit
9984edcbf3
  1. 7
      disco/gateway/client.py

7
disco/gateway/client.py

@ -2,6 +2,7 @@ import gevent
import zlib
import six
import ssl
import time
import platform
from websocket import ABNF
@ -71,6 +72,10 @@ class GatewayClient(LoggingClass):
self._heartbeat_task = None
self._heartbeat_acknowledged = True
# Latency
self._last_heartbeat = 0
self.latency = -1
def send(self, op, data):
self.limiter.check()
return self._send(op, data)
@ -90,6 +95,7 @@ class GatewayClient(LoggingClass):
self._heartbeat_acknowledged = True
self.ws.close(status=4000)
return
self._last_heartbeat = time.time()
self._send(OPCode.HEARTBEAT, self.seq)
self._heartbeat_acknowledged = False
@ -108,6 +114,7 @@ class GatewayClient(LoggingClass):
def handle_heartbeat_acknowledge(self, _):
self.log.debug('Received HEARTBEAT_ACK')
self._heartbeat_acknowledged = True
self.latency = int((time.time() - self._last_heartbeat) * 1000)
def handle_reconnect(self, _):
self.log.warning('Received RECONNECT request, forcing a fresh reconnect')

Loading…
Cancel
Save