From f6fa1e837a3672d7e6cc276a58a71c7c8cf7eca7 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 2 Jun 2016 07:32:35 -0400 Subject: [PATCH] Actually use v4 gateway and fixes thanks to Jake. --- discord/endpoints.py | 2 +- discord/gateway.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/endpoints.py b/discord/endpoints.py index ac99f74ff..0ef0efa96 100644 --- a/discord/endpoints.py +++ b/discord/endpoints.py @@ -26,7 +26,7 @@ DEALINGS IN THE SOFTWARE. BASE = 'https://discordapp.com' API_BASE = BASE + '/api' -GATEWAY = API_BASE + '/gateway?encoding=json&v=4' +GATEWAY = API_BASE + '/gateway' USERS = API_BASE + '/users' ME = USERS + '/@me' REGISTER = API_BASE + '/auth/register' diff --git a/discord/gateway.py b/discord/gateway.py index 4d2c9cca3..a569e4642 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -125,7 +125,7 @@ def get_gateway(token, *, loop=None): yield from resp.release() raise GatewayNotFound() data = yield from resp.json(encoding='utf-8') - return data.get('url') + return data.get('url') + '?encoding=json&v=4' class DiscordWebSocket(websockets.client.WebSocketClientProtocol): """Implements a WebSocket for Discord's gateway v4. @@ -310,6 +310,9 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): if op == self.INVALIDATE_SESSION: state.sequence = None state.session_id = None + if data == True: + raise ResumeWebSocket() + yield from self.identify() return @@ -381,10 +384,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): except websockets.exceptions.ConnectionClosed as e: if self._can_handle_close(e.code): log.info('Websocket closed with {0.code} ({0.reason}), attempting a reconnect.'.format(e)) - if e.code == 4006: - raise ReconnectWebSocket() from e - else: - raise ResumeWebSocket() from e + raise ResumeWebSocket() from e else: raise ConnectionClosed(e) from e