diff --git a/hikari/api/rest.py b/hikari/api/rest.py index 10bae2486a..b6fe289ded 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -783,8 +783,8 @@ async def create_message( @abc.abstractmethod async def edit_message( self, - channel: typing.Union[snowflakes.SnowflakeishOr[channels.TextChannel]], - message: typing.Union[snowflakes.SnowflakeishOr[messages_.Message]], + channel: snowflakes.SnowflakeishOr[channels.TextChannel], + message: snowflakes.SnowflakeishOr[messages_.Message], content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, @@ -1981,7 +1981,7 @@ async def create_guild_category( async def reposition_channels( self, guild: snowflakes.SnowflakeishOr[guilds.PartialGuild], - positions: typing.Mapping[int, typing.Union[snowflakes.SnowflakeishOr[channels.GuildChannel]]], + positions: typing.Mapping[int, snowflakes.SnowflakeishOr[channels.GuildChannel]], ) -> None: ... diff --git a/hikari/impl/bot.py b/hikari/impl/bot.py index d3a76e8667..c70a788bd3 100644 --- a/hikari/impl/bot.py +++ b/hikari/impl/bot.py @@ -665,9 +665,14 @@ async def start( if requirements.session_start_limit.remaining < len(shard_ids) and not ignore_session_start_limit: _LOGGER.critical( - "would have started %s session(s), but you only have %s remaining until %s. Starting more sessions " - "than you are allowed to start may result in your token being reset. To skip this message, " - "use bot.run(..., ignore_session_start_limit=True) or bot.start(..., ignore_session_start_limit=True)" + "would have started %s session%s, but you only have %s session%s remaining until %s. Starting more " + "sessions than you are allowed to start may result in your token being reset. To skip this message, " + "use bot.run(..., ignore_session_start_limit=True) or bot.start(..., ignore_session_start_limit=True)", + len(shard_ids), + "s" if len(shard_ids) != 1 else "", + requirements.session_start_limit.remaining, + "s" if requirements.session_start_limit.remaining != 1 else "", + requirements.session_start_limit.reset_at, ) raise errors.GatewayError("Attempted to start more sessions than were allowed in the given time-window") diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index 631c53135b..91fe6bd772 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1004,8 +1004,8 @@ async def create_message( async def edit_message( self, - channel: typing.Union[snowflakes.SnowflakeishOr[channels.TextChannel]], - message: typing.Union[snowflakes.SnowflakeishOr[messages_.Message]], + channel: snowflakes.SnowflakeishOr[channels.TextChannel], + message: snowflakes.SnowflakeishOr[messages_.Message], content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, @@ -1902,7 +1902,7 @@ async def _create_guild_channel( async def reposition_channels( self, guild: snowflakes.SnowflakeishOr[guilds.PartialGuild], - positions: typing.Mapping[int, typing.Union[snowflakes.SnowflakeishOr[channels.GuildChannel]]], + positions: typing.Mapping[int, snowflakes.SnowflakeishOr[channels.GuildChannel]], ) -> None: route = routes.POST_GUILD_CHANNELS.compile(guild=guild) body = [{"id": str(int(channel)), "position": pos} for pos, channel in positions.items()] diff --git a/hikari/impl/shard.py b/hikari/impl/shard.py index 61b0803f24..0a0ce4effa 100644 --- a/hikari/impl/shard.py +++ b/hikari/impl/shard.py @@ -149,9 +149,9 @@ async def _receive_and_check(self, timeout: typing.Optional[float], /) -> str: self._logger.error("connection closed with code %s (%s)", close_code, reason) can_reconnect = close_code < 4000 or close_code in ( + errors.ShardCloseCode.UNKNOWN_ERROR, errors.ShardCloseCode.DECODE_ERROR, errors.ShardCloseCode.INVALID_SEQ, - errors.ShardCloseCode.UNKNOWN_ERROR, errors.ShardCloseCode.SESSION_TIMEOUT, errors.ShardCloseCode.RATE_LIMITED, ) @@ -162,13 +162,18 @@ async def _receive_and_check(self, timeout: typing.Optional[float], /) -> str: elif message.type == aiohttp.WSMsgType.CLOSING or message.type == aiohttp.WSMsgType.CLOSED: raise asyncio.CancelledError("Socket closed") + elif len(buff) != 0 and message.type != aiohttp.WSMsgType.BINARY: + raise errors.GatewayError(f"Unexpected message type received {message.type.name}, expected BINARY") + elif message.type == aiohttp.WSMsgType.BINARY: - buff += message.data + buff.extend(message.data) if buff.endswith(b"\x00\x00\xff\xff"): return self._zlib.decompress(buff).decode("utf-8") + elif message.type == aiohttp.WSMsgType.TEXT: return message.data # type: ignore + else: # Assume exception for now. ex = self.exception() @@ -192,8 +197,8 @@ async def connect( *, debug: bool, http_config: config.HTTPSettings, - logger: logging.Logger, proxy_config: config.ProxySettings, + logger: logging.Logger, url: str, ) -> typing.AsyncGenerator[_V6GatewayTransport, None]: """Generate a single-use websocket connection. @@ -809,9 +814,10 @@ async def _run_once(self) -> bool: ) return True return False - finally: + finally: heartbeat_task.cancel() + finally: self._ws = None if dispatch_disconnect: