From b8154e365ff584438a8d42354e56881e550bb72e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 7 Apr 2020 21:53:55 -0400 Subject: Rewrite gateway to use aiohttp instead of websockets --- discord/shard.py | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'discord/shard.py') diff --git a/discord/shard.py b/discord/shard.py index f2feaecb..1e34a56c 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -28,8 +28,6 @@ import asyncio import itertools import logging -import websockets - from .state import AutoShardedConnectionState from .client import Client from .gateway import * @@ -191,31 +189,13 @@ class AutoShardedClient(Client): async def launch_shard(self, gateway, shard_id): try: - coro = websockets.connect(gateway, loop=self.loop, klass=DiscordWebSocket, compression=None) + coro = DiscordWebSocket.from_client(self, gateway=gateway, shard_id=shard_id) ws = await asyncio.wait_for(coro, timeout=180.0) except Exception: log.info('Failed to connect for shard_id: %s. Retrying...', shard_id) await asyncio.sleep(5.0) return await self.launch_shard(gateway, shard_id) - ws.token = self.http.token - ws._connection = self._connection - ws._discord_parsers = self._connection.parsers - ws._dispatch = self.dispatch - ws.gateway = gateway - ws.shard_id = shard_id - ws.shard_count = self.shard_count - ws._max_heartbeat_timeout = self._connection.heartbeat_timeout - - try: - # OP HELLO - await asyncio.wait_for(ws.poll_event(), timeout=180.0) - await asyncio.wait_for(ws.identify(), timeout=180.0) - except asyncio.TimeoutError: - log.info('Timed out when connecting for shard_id: %s. Retrying...', shard_id) - await asyncio.sleep(5.0) - return await self.launch_shard(gateway, shard_id) - # keep reading the shard while others connect self.shards[shard_id] = ret = Shard(ws, self) ret.launch() -- cgit v1.2.3