diff options
| author | Rapptz <[email protected]> | 2020-04-07 21:53:55 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-07-25 09:59:38 -0400 |
| commit | b8154e365ff584438a8d42354e56881e550bb72e (patch) | |
| tree | 799c9bb73c25731a87cb12c04a35b420260f8970 /discord/shard.py | |
| parent | Fix AttributeError on reconnection (diff) | |
| download | discord.py-b8154e365ff584438a8d42354e56881e550bb72e.tar.xz discord.py-b8154e365ff584438a8d42354e56881e550bb72e.zip | |
Rewrite gateway to use aiohttp instead of websockets
Diffstat (limited to 'discord/shard.py')
| -rw-r--r-- | discord/shard.py | 22 |
1 files changed, 1 insertions, 21 deletions
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() |