diff options
| author | Rapptz <[email protected]> | 2015-08-26 22:26:06 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-08-26 22:26:06 -0400 |
| commit | 29b71a7e88602fec594b2643bd234cc789c7829a (patch) | |
| tree | b128b890341f95cfdf56966ca7aa73ba6708fed4 /discord/client.py | |
| parent | Parse roles in the member building. (diff) | |
| download | discord.py-29b71a7e88602fec594b2643bd234cc789c7829a.tar.xz discord.py-29b71a7e88602fec594b2643bd234cc789c7829a.zip | |
Move websocket hub to the new gateway.
Diffstat (limited to 'discord/client.py')
| -rw-r--r-- | discord/client.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py index b9d0350e..73f7c956 100644 --- a/discord/client.py +++ b/discord/client.py @@ -31,7 +31,7 @@ from collections import deque from threading import Timer from ws4py.client.threadedclient import WebSocketClient from sys import platform as sys_platform -from errors import InvalidEventName, InvalidDestination +from errors import InvalidEventName, InvalidDestination, GatewayNotFound from user import User from channel import Channel, PrivateChannel from server import Server, Member, Permissions, Role @@ -100,7 +100,15 @@ class Client(object): 'on_channel_create': _null_event, } - self.ws = WebSocketClient(endpoints.WEBSOCKET_HUB, protocols=['http-only', 'chat']) + gateway = requests.get(endpoints.GATEWAY) + if gateway.status_code != 200: + raise GatewayNotFound() + gateway_js = gateway.json() + url = gateway_js.get('url') + if url is None: + raise GatewayNotFound() + + self.ws = WebSocketClient(url, protocols=['http-only', 'chat']) # this is kind of hacky, but it's to avoid deadlocks. # i.e. python does not allow me to have the current thread running if it's self |