aboutsummaryrefslogtreecommitdiff
path: root/discord/client.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-25 01:53:35 -0500
committerRapptz <[email protected]>2016-01-25 01:55:31 -0500
commit8b1854e759a28a1ecd84bdc80f5a50722fb9f2db (patch)
tree665ea7034a766efa7f0ec137473e1ff6a31a1c3f /discord/client.py
parentHTTPException now has a text attribute if JSON is not available. (diff)
downloaddiscord.py-8b1854e759a28a1ecd84bdc80f5a50722fb9f2db.tar.xz
discord.py-8b1854e759a28a1ecd84bdc80f5a50722fb9f2db.zip
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.
Diffstat (limited to 'discord/client.py')
-rw-r--r--discord/client.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/discord/client.py b/discord/client.py
index 83a7325c..2b3ab45a 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -148,6 +148,11 @@ class Client:
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:
log.info('attempting to login via cache')
@@ -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)