From 8b1854e759a28a1ecd84bdc80f5a50722fb9f2db Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 25 Jan 2016 01:53:35 -0500 Subject: Add and remove some of the on_socket_* events. on_socket_raw_receive and on_socket_raw_send were added back in an odd way. The rest of them such as on_socket_closed, on_socket_opened, and on_socket_receive were removed. --- discord/client.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'discord') diff --git a/discord/client.py b/discord/client.py index 83a7325c..2b3ab45a 100644 --- a/discord/client.py +++ b/discord/client.py @@ -147,6 +147,11 @@ class Client: filename = hashlib.md5(email.encode('utf-8')).hexdigest() return os.path.join(tempfile.gettempdir(), 'discord_py', filename) + @asyncio.coroutine + def _send_ws(self, data): + self.dispatch('socket_raw_send', data) + yield from self.ws.send(data) + @asyncio.coroutine def _login_via_cache(self, email, password): try: @@ -282,7 +287,7 @@ class Client: msg = 'Keeping websocket alive with timestamp {}' log.debug(msg.format(payload['d'])) - yield from self.ws.send(utils.to_json(payload)) + yield from self._send_ws(utils.to_json(payload)) yield from asyncio.sleep(interval) except asyncio.CancelledError: pass @@ -302,6 +307,8 @@ class Client: @asyncio.coroutine def received_message(self, msg): + self.dispatch('socket_raw_receive', msg) + if isinstance(msg, bytes): msg = zlib.decompress(msg, 15, 10490000) # This is 10 MiB msg = msg.decode('utf-8') @@ -386,7 +393,7 @@ class Client: } } - yield from self.ws.send(utils.to_json(payload)) + yield from self._send_ws(utils.to_json(payload)) log.info('sent the initial payload to create the websocket') @asyncio.coroutine @@ -415,7 +422,7 @@ class Client: } log.info('sending reconnection frame to websocket {}'.format(payload)) - yield from self.ws.send(utils.to_json(payload)) + yield from self._send_ws(utils.to_json(payload)) # login state management @@ -1462,7 +1469,7 @@ class Client: sent = utils.to_json(payload) log.debug('Sending "{}" to change status'.format(sent)) - yield from self.ws.send(sent) + yield from self._send_ws(sent) # Channel management @@ -2431,7 +2438,7 @@ class Client: } } - yield from self.ws.send(utils.to_json(payload)) + yield from self._send_ws(utils.to_json(payload)) yield from asyncio.wait_for(self._session_id_found.wait(), timeout=5.0, loop=self.loop) yield from asyncio.wait_for(self._voice_data_found.wait(), timeout=5.0, loop=self.loop) -- cgit v1.2.3