|
@ -127,6 +127,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
INVALIDATE_SESSION |
|
|
INVALIDATE_SESSION |
|
|
Receive only. Tells the client to invalidate the session and IDENTIFY |
|
|
Receive only. Tells the client to invalidate the session and IDENTIFY |
|
|
again. |
|
|
again. |
|
|
|
|
|
HELLO |
|
|
|
|
|
Receive only. Tells the client the heartbeat interval. |
|
|
|
|
|
HEARTBEAT_ACK |
|
|
|
|
|
Receive only. Confirms receiving of a heartbeat. Not having it implies |
|
|
|
|
|
a connection issue. |
|
|
|
|
|
GUILD_SYNC |
|
|
|
|
|
Send only. Requests a guild sync. |
|
|
gateway |
|
|
gateway |
|
|
The gateway we are currently connected to. |
|
|
The gateway we are currently connected to. |
|
|
token |
|
|
token |
|
@ -143,6 +150,9 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
RECONNECT = 7 |
|
|
RECONNECT = 7 |
|
|
REQUEST_MEMBERS = 8 |
|
|
REQUEST_MEMBERS = 8 |
|
|
INVALIDATE_SESSION = 9 |
|
|
INVALIDATE_SESSION = 9 |
|
|
|
|
|
HELLO = 10 |
|
|
|
|
|
HEARTBEAT_ACK = 11 |
|
|
|
|
|
GUILD_SYNC = 12 |
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
def __init__(self, *args, **kwargs): |
|
|
super().__init__(*args, max_size=None, **kwargs) |
|
|
super().__init__(*args, max_size=None, **kwargs) |
|
@ -172,6 +182,10 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
client.connection._update_references(ws) |
|
|
client.connection._update_references(ws) |
|
|
|
|
|
|
|
|
log.info('Created websocket connected to {}'.format(gateway)) |
|
|
log.info('Created websocket connected to {}'.format(gateway)) |
|
|
|
|
|
|
|
|
|
|
|
# poll the event for OP HELLO |
|
|
|
|
|
yield from ws.poll_event() |
|
|
|
|
|
|
|
|
if not resume: |
|
|
if not resume: |
|
|
yield from ws.identify() |
|
|
yield from ws.identify() |
|
|
log.info('sent the identify payload to create the websocket') |
|
|
log.info('sent the identify payload to create the websocket') |
|
@ -232,6 +246,10 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
'v': 3 |
|
|
'v': 3 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if not self._connection.is_bot: |
|
|
|
|
|
payload['d']['synced_guilds'] = [] |
|
|
|
|
|
|
|
|
yield from self.send_as_json(payload) |
|
|
yield from self.send_as_json(payload) |
|
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
@asyncio.coroutine |
|
@ -277,6 +295,12 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
yield from self.close() |
|
|
yield from self.close() |
|
|
raise ReconnectWebSocket() |
|
|
raise ReconnectWebSocket() |
|
|
|
|
|
|
|
|
|
|
|
if op == self.HELLO: |
|
|
|
|
|
interval = data['heartbeat_interval'] / 1000.0 |
|
|
|
|
|
self._keep_alive = KeepAliveHandler(ws=self, interval=interval) |
|
|
|
|
|
self._keep_alive.start() |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if op == self.INVALIDATE_SESSION: |
|
|
if op == self.INVALIDATE_SESSION: |
|
|
state.sequence = None |
|
|
state.sequence = None |
|
|
state.session_id = None |
|
|
state.session_id = None |
|
@ -298,11 +322,6 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
state.sequence = msg['s'] |
|
|
state.sequence = msg['s'] |
|
|
state.session_id = data['session_id'] |
|
|
state.session_id = data['session_id'] |
|
|
|
|
|
|
|
|
if is_ready or event == 'RESUMED': |
|
|
|
|
|
interval = data['heartbeat_interval'] / 1000.0 |
|
|
|
|
|
self._keep_alive = KeepAliveHandler(ws=self, interval=interval) |
|
|
|
|
|
self._keep_alive.start() |
|
|
|
|
|
|
|
|
|
|
|
parser = 'parse_' + event.lower() |
|
|
parser = 'parse_' + event.lower() |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
@ -400,6 +419,14 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
status = Status.idle if idle_since else Status.online |
|
|
status = Status.idle if idle_since else Status.online |
|
|
me.status = status |
|
|
me.status = status |
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
|
|
|
def request_sync(self, guild_ids): |
|
|
|
|
|
payload = { |
|
|
|
|
|
'op': self.GUILD_SYNC, |
|
|
|
|
|
'd': list(guild_ids) |
|
|
|
|
|
} |
|
|
|
|
|
yield from self.send_as_json(payload) |
|
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
@asyncio.coroutine |
|
|
def voice_state(self, guild_id, channel_id, self_mute=False, self_deaf=False): |
|
|
def voice_state(self, guild_id, channel_id, self_mute=False, self_deaf=False): |
|
|
payload = { |
|
|
payload = { |
|
|