diff options
| author | Rapptz <[email protected]> | 2016-01-01 21:08:43 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-01-01 21:08:43 -0500 |
| commit | 080b8119adcab6f5dc72010f215f438d633a36d1 (patch) | |
| tree | 62260a3c38d4c113966b45a57c57e3044548d9c3 | |
| parent | Actually send the payload data in Client.create_server (diff) | |
| download | discord.py-080b8119adcab6f5dc72010f215f438d633a36d1.tar.xz discord.py-080b8119adcab6f5dc72010f215f438d633a36d1.zip | |
Implement compressed READY
| -rw-r--r-- | discord/client.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py index 6bb4b036..add57333 100644 --- a/discord/client.py +++ b/discord/client.py @@ -50,6 +50,7 @@ import logging, traceback import sys, time, re, json import tempfile, os, hashlib import itertools +import zlib log = logging.getLogger(__name__) request_logging_format = '{method} {response.url} has returned {response.status}' @@ -298,6 +299,13 @@ class Client: @asyncio.coroutine def received_message(self, msg): + if isinstance(msg, bytes): + print('compressed') + msg = zlib.decompress(msg, 15, 10490000) # This is 10 MiB + msg = msg.decode('utf-8') + + msg = json.loads(msg) + log.debug('WebSocket Event: {}'.format(msg)) self.dispatch('socket_response', msg) @@ -367,6 +375,7 @@ class Client: '$referrer': '', '$referring_domain': '' }, + 'compress': True, 'v': 3 } } @@ -698,7 +707,7 @@ class Client: yield from self.close() break - yield from self.received_message(json.loads(msg)) + yield from self.received_message(msg) @asyncio.coroutine def close(self): |