Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions interactions/api/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ async def run(self) -> None:
seq = msg.get("s")
event = msg.get("t")

if op == MISSING:
# Internal no-op, ignore it.
continue

if seq:
self.sequence = seq

Expand Down
10 changes: 9 additions & 1 deletion interactions/api/gateway/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def send_json(self, data: dict, bypass=False) -> None:
serialized = FastJson.dumps(data)
await self.send(serialized, bypass)

async def receive(self, force: bool = False) -> str: # noqa: C901
async def receive(self, force: bool = False) -> dict: # noqa: C901
"""
Receive a full event payload from the WebSocket.

Expand Down Expand Up @@ -208,6 +208,14 @@ async def receive(self, force: bool = False) -> str: # noqa: C901
# is possible after all we can just wait for the event to be set.
await self._closed.wait()
else:
if self.state.client.http.closed:
# On aiohttp>=3.12.4, the aiohttp WebSocket client will always send a session
# close message when the underlying HTTP connection is closed. We want to
# ignore this to keep the behavior consistent with previous versions
# of Python, so we return this to indicate that no message was received.
# https://github.com/interactions-py/interactions.py/issues/1778
return {"op": const.MISSING}

# This is an odd corner-case where the underlying socket connection was closed
# unexpectedly without communicating the WebSocket closing handshake. We'll have
# to reconnect ourselves.
Expand Down
11 changes: 11 additions & 0 deletions interactions/api/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ def __init__(
logger = constants.get_logger()
self.logger = logger

@property
def closed(self) -> bool:
"""
Returns whether the session is closed.

Returns:
True if the session is closed, False otherwise.

"""
return self.__session is None or self.__session.closed

def get_ratelimit(self, route: Route) -> BucketLock:
"""
Get a route's rate limit bucket.
Expand Down
Loading