Skip to content

Commit 3863a83

Browse files
author
Nekokatt
authored
Merge pull request #136 from davfsa/task/several-bugfixes
Several bug fixes
2 parents 51d815b + 0f39b7f commit 3863a83

4 files changed

Lines changed: 24 additions & 13 deletions

File tree

hikari/api/rest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,8 @@ async def create_message(
783783
@abc.abstractmethod
784784
async def edit_message(
785785
self,
786-
channel: typing.Union[snowflakes.SnowflakeishOr[channels.TextChannel]],
787-
message: typing.Union[snowflakes.SnowflakeishOr[messages_.Message]],
786+
channel: snowflakes.SnowflakeishOr[channels.TextChannel],
787+
message: snowflakes.SnowflakeishOr[messages_.Message],
788788
content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED,
789789
*,
790790
embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED,
@@ -1981,7 +1981,7 @@ async def create_guild_category(
19811981
async def reposition_channels(
19821982
self,
19831983
guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
1984-
positions: typing.Mapping[int, typing.Union[snowflakes.SnowflakeishOr[channels.GuildChannel]]],
1984+
positions: typing.Mapping[int, snowflakes.SnowflakeishOr[channels.GuildChannel]],
19851985
) -> None:
19861986
...
19871987

hikari/impl/bot.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,14 @@ async def start(
665665

666666
if requirements.session_start_limit.remaining < len(shard_ids) and not ignore_session_start_limit:
667667
_LOGGER.critical(
668-
"would have started %s session(s), but you only have %s remaining until %s. Starting more sessions "
669-
"than you are allowed to start may result in your token being reset. To skip this message, "
670-
"use bot.run(..., ignore_session_start_limit=True) or bot.start(..., ignore_session_start_limit=True)"
668+
"would have started %s session%s, but you only have %s session%s remaining until %s. Starting more "
669+
"sessions than you are allowed to start may result in your token being reset. To skip this message, "
670+
"use bot.run(..., ignore_session_start_limit=True) or bot.start(..., ignore_session_start_limit=True)",
671+
len(shard_ids),
672+
"s" if len(shard_ids) != 1 else "",
673+
requirements.session_start_limit.remaining,
674+
"s" if requirements.session_start_limit.remaining != 1 else "",
675+
requirements.session_start_limit.reset_at,
671676
)
672677
raise errors.GatewayError("Attempted to start more sessions than were allowed in the given time-window")
673678

hikari/impl/rest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ async def create_message(
10041004

10051005
async def edit_message(
10061006
self,
1007-
channel: typing.Union[snowflakes.SnowflakeishOr[channels.TextChannel]],
1008-
message: typing.Union[snowflakes.SnowflakeishOr[messages_.Message]],
1007+
channel: snowflakes.SnowflakeishOr[channels.TextChannel],
1008+
message: snowflakes.SnowflakeishOr[messages_.Message],
10091009
content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED,
10101010
*,
10111011
embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED,
@@ -1902,7 +1902,7 @@ async def _create_guild_channel(
19021902
async def reposition_channels(
19031903
self,
19041904
guild: snowflakes.SnowflakeishOr[guilds.PartialGuild],
1905-
positions: typing.Mapping[int, typing.Union[snowflakes.SnowflakeishOr[channels.GuildChannel]]],
1905+
positions: typing.Mapping[int, snowflakes.SnowflakeishOr[channels.GuildChannel]],
19061906
) -> None:
19071907
route = routes.POST_GUILD_CHANNELS.compile(guild=guild)
19081908
body = [{"id": str(int(channel)), "position": pos} for pos, channel in positions.items()]

hikari/impl/shard.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ async def _receive_and_check(self, timeout: typing.Optional[float], /) -> str:
149149
self._logger.error("connection closed with code %s (%s)", close_code, reason)
150150

151151
can_reconnect = close_code < 4000 or close_code in (
152+
errors.ShardCloseCode.UNKNOWN_ERROR,
152153
errors.ShardCloseCode.DECODE_ERROR,
153154
errors.ShardCloseCode.INVALID_SEQ,
154-
errors.ShardCloseCode.UNKNOWN_ERROR,
155155
errors.ShardCloseCode.SESSION_TIMEOUT,
156156
errors.ShardCloseCode.RATE_LIMITED,
157157
)
@@ -162,13 +162,18 @@ async def _receive_and_check(self, timeout: typing.Optional[float], /) -> str:
162162
elif message.type == aiohttp.WSMsgType.CLOSING or message.type == aiohttp.WSMsgType.CLOSED:
163163
raise asyncio.CancelledError("Socket closed")
164164

165+
elif len(buff) != 0 and message.type != aiohttp.WSMsgType.BINARY:
166+
raise errors.GatewayError(f"Unexpected message type received {message.type.name}, expected BINARY")
167+
165168
elif message.type == aiohttp.WSMsgType.BINARY:
166-
buff += message.data
169+
buff.extend(message.data)
167170

168171
if buff.endswith(b"\x00\x00\xff\xff"):
169172
return self._zlib.decompress(buff).decode("utf-8")
173+
170174
elif message.type == aiohttp.WSMsgType.TEXT:
171175
return message.data # type: ignore
176+
172177
else:
173178
# Assume exception for now.
174179
ex = self.exception()
@@ -192,8 +197,8 @@ async def connect(
192197
*,
193198
debug: bool,
194199
http_config: config.HTTPSettings,
195-
logger: logging.Logger,
196200
proxy_config: config.ProxySettings,
201+
logger: logging.Logger,
197202
url: str,
198203
) -> typing.AsyncGenerator[_V6GatewayTransport, None]:
199204
"""Generate a single-use websocket connection.
@@ -809,9 +814,10 @@ async def _run_once(self) -> bool:
809814
)
810815
return True
811816
return False
812-
finally:
813817

818+
finally:
814819
heartbeat_task.cancel()
820+
815821
finally:
816822
self._ws = None
817823
if dispatch_disconnect:

0 commit comments

Comments
 (0)