mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Actually use v4 gateway and fixes thanks to Jake.
This commit is contained in:
parent
c97e5a17e6
commit
f6fa1e837a
@ -26,7 +26,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
BASE = 'https://discordapp.com'
|
BASE = 'https://discordapp.com'
|
||||||
API_BASE = BASE + '/api'
|
API_BASE = BASE + '/api'
|
||||||
GATEWAY = API_BASE + '/gateway?encoding=json&v=4'
|
GATEWAY = API_BASE + '/gateway'
|
||||||
USERS = API_BASE + '/users'
|
USERS = API_BASE + '/users'
|
||||||
ME = USERS + '/@me'
|
ME = USERS + '/@me'
|
||||||
REGISTER = API_BASE + '/auth/register'
|
REGISTER = API_BASE + '/auth/register'
|
||||||
|
@ -125,7 +125,7 @@ def get_gateway(token, *, loop=None):
|
|||||||
yield from resp.release()
|
yield from resp.release()
|
||||||
raise GatewayNotFound()
|
raise GatewayNotFound()
|
||||||
data = yield from resp.json(encoding='utf-8')
|
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):
|
class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||||
"""Implements a WebSocket for Discord's gateway v4.
|
"""Implements a WebSocket for Discord's gateway v4.
|
||||||
@ -310,6 +310,9 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
if op == self.INVALIDATE_SESSION:
|
if op == self.INVALIDATE_SESSION:
|
||||||
state.sequence = None
|
state.sequence = None
|
||||||
state.session_id = None
|
state.session_id = None
|
||||||
|
if data == True:
|
||||||
|
raise ResumeWebSocket()
|
||||||
|
|
||||||
yield from self.identify()
|
yield from self.identify()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -381,9 +384,6 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
if self._can_handle_close(e.code):
|
if self._can_handle_close(e.code):
|
||||||
log.info('Websocket closed with {0.code} ({0.reason}), attempting a reconnect.'.format(e))
|
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:
|
else:
|
||||||
raise ConnectionClosed(e) from e
|
raise ConnectionClosed(e) from e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user