aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-06-02 07:32:35 -0400
committerRapptz <[email protected]>2016-06-02 07:32:35 -0400
commitf6fa1e837a3672d7e6cc276a58a71c7c8cf7eca7 (patch)
tree29608f01479a220e3d3f24163f7c18b36f263002
parentUpdate positions when a role is added or removed. (diff)
downloaddiscord.py-f6fa1e837a3672d7e6cc276a58a71c7c8cf7eca7.tar.xz
discord.py-f6fa1e837a3672d7e6cc276a58a71c7c8cf7eca7.zip
Actually use v4 gateway and fixes thanks to Jake.
-rw-r--r--discord/endpoints.py2
-rw-r--r--discord/gateway.py10
2 files changed, 6 insertions, 6 deletions
diff --git a/discord/endpoints.py b/discord/endpoints.py
index ac99f74f..0ef0efa9 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 4d2c9cca..a569e464 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