diff options
| author | Rapptz <[email protected]> | 2017-02-08 04:37:16 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-02-08 04:37:16 -0500 |
| commit | dc486980f87249583a38a22c79aa0f7370b75d55 (patch) | |
| tree | e2c6b091c40469e51e358b0c736bd81e29137e4f /discord/gateway.py | |
| parent | Only defer the lock if we're pre-emptively rate limiting. (diff) | |
| download | discord.py-dc486980f87249583a38a22c79aa0f7370b75d55.tar.xz discord.py-dc486980f87249583a38a22c79aa0f7370b75d55.zip | |
Rewrite RESUME logic to be more in line with what is requested.
Apparently we should always try to RESUME first and if we get
INVALIDATE_SESSION then we should IDENTIFY instead. This is the
preferred way to do RESUMEs.
Diffstat (limited to 'discord/gateway.py')
| -rw-r--r-- | discord/gateway.py | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/discord/gateway.py b/discord/gateway.py index 9897ca42..e75370bc 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -41,15 +41,9 @@ import struct log = logging.getLogger(__name__) -__all__ = [ 'ReconnectWebSocket', 'DiscordWebSocket', - 'KeepAliveHandler', 'VoiceKeepAliveHandler', +__all__ = [ 'DiscordWebSocket', 'KeepAliveHandler', 'VoiceKeepAliveHandler', 'DiscordVoiceWebSocket', 'ResumeWebSocket' ] -class ReconnectWebSocket(Exception): - """Signals to handle the RECONNECT opcode.""" - def __init__(self, shard_id): - self.shard_id = shard_id - class ResumeWebSocket(Exception): """Signals to initialise via RESUME opcode instead of IDENTIFY.""" def __init__(self, shard_id): @@ -128,8 +122,8 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): REQUEST_MEMBERS Send only. Asks for the full member list of a guild. INVALIDATE_SESSION - Receive only. Tells the client to invalidate the session and IDENTIFY - again. + Receive only. Tells the client to optionally invalidate the session + and IDENTIFY again. HELLO Receive only. Tells the client the heartbeat interval. HEARTBEAT_ACK @@ -306,7 +300,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): # internal exception signalling to reconnect. log.info('Received RECONNECT opcode.') yield from self.close() - raise ReconnectWebSocket(self.shard_id) + raise ResumeWebSocket(self.shard_id) if op == self.HEARTBEAT_ACK: return # disable noisy logging for now @@ -323,12 +317,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): return if op == self.INVALIDATE_SESSION: - self.sequence = None - self.session_id = None if data == True: yield from self.close() raise ResumeWebSocket(self.shard_id) + self.sequence = None + self.session_id = None + log.info('Shard ID %s has either failed a RESUME request or needed to invalidate its session.' % self.shard_id) yield from self.identify() return |