fix: shard imports

This commit is contained in:
grey-cat-1908 2022-04-22 08:38:45 +03:00
parent e539528e71
commit 725432162d
4 changed files with 20 additions and 14 deletions

View file

@ -9,10 +9,10 @@ from .rest import RESTApp
from .core.gateway import GatewayBotInfo from .core.gateway import GatewayBotInfo
from .models.guild.channel import Channel, ChannelType, channel_types_for_converting from .models.guild.channel import Channel, ChannelType, channel_types_for_converting
from .models import User, Guild, Activity from .models import User, Guild, Activity
from .models.app import Shard from .models.app.shard import Shard
from .models.app.intents import Intents from .models.app.intents import Intents
from .utils.snowflake import Snowflake from .utils.snowflake import Snowflake
from .utils import APIModelBase from .utils.api_model import APIModelBase
from .utils.logging import init_logging from .utils.logging import init_logging
from .utils.types import Coro from .utils.types import Coro
from .utils.waiters import WaiterMgr from .utils.waiters import WaiterMgr

View file

@ -78,6 +78,7 @@ class Gateway:
self.listeners = listeners self.listeners = listeners
self._last_send = 0 self._last_send = 0
self._max_connect_retries = 5
self.auth = { self.auth = {
"token": self.client._token, "token": self.client._token,
@ -100,18 +101,24 @@ class Gateway:
self._buffer: bytearray = bytearray() self._buffer: bytearray = bytearray()
async def connect(self) -> None: async def connect(self) -> None:
self.ws = await self.__session.ws_connect( try:
"wss://gateway.discord.gg/?v=10&encoding=json&compress=zlib-stream" self.ws = await self.__session.ws_connect(
) "wss://gateway.discord.gg/?v=10&encoding=json&compress=zlib-stream",
_logger.debug("(Shard %s) Starting...", self.shard_id) timeout=30.0
)
_logger.debug("(Shard %s) Starting...", self.shard_id)
self._zlib: zlib._Decompress = zlib.decompressobj() self._zlib: zlib._Decompress = zlib.decompressobj()
self._buffer = bytearray() self._buffer = bytearray()
self.not_closed = True self.not_closed = True
await self.send_identify() await self.send_identify()
self.loop.create_task(self.receive()) self.loop.create_task(self.receive())
await self.check_heartbeating() await self.check_heartbeating()
except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as exc:
_logger.error("(Shard %s) Connecting failed!", self.shard_id)
raise exc
async def check_heartbeating(self): async def check_heartbeating(self):
while self.not_closed: while self.not_closed:

View file

@ -1,7 +1,7 @@
# Copyright MelisaDev 2022 - Present # Copyright MelisaDev 2022 - Present
# Full MIT License can be found in `LICENSE.txt` at the project root. # Full MIT License can be found in `LICENSE.txt` at the project root.
from .app import Shard, Intents from .app import Intents
from .guild import * from .guild import *
from .user import * from .user import *
from .message import * from .message import *

View file

@ -2,4 +2,3 @@
# Full MIT License can be found in `LICENSE.txt` at the project root. # Full MIT License can be found in `LICENSE.txt` at the project root.
from .intents import Intents from .intents import Intents
from .shard import Shard