Skip to content

Commit 7a2fc27

Browse files
committed
fix: Change to int value conversions for payload, readd afk attribute to ClientPresence object, revert suppress 4001 commit.
1 parent 8d9c275 commit 7a2fc27

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

interactions/api/gateway/client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,7 @@ async def __receive_packet(self, ignore_lock: bool = False) -> Optional[Dict[str
748748
if packet.type == WSMsgType.CLOSE:
749749
log.debug(f"Disconnecting from gateway = {packet.data}::{packet.extra}")
750750

751-
if (
752-
packet.data >= 4000 and packet.data != 4001
753-
): # suppress 4001 because of weird presence errors
751+
if packet.data >= 4000: # suppress 4001 because of weird presence errors
754752
# This means that the error code is 4000+, which may signify Discord-provided error codes.
755753

756754
# However, we suppress 4001 because of weird presence errors with change_presence
@@ -807,7 +805,7 @@ async def _send_packet(self, data: Dict[str, Any]) -> None:
807805
_data = dumps(data) if isinstance(data, dict) else data
808806
packet: str = _data.decode("utf-8") if isinstance(_data, bytes) else _data
809807

810-
if data["op"] != OpCodeType.HEARTBEAT:
808+
if data["op"] != OpCodeType.HEARTBEAT.value:
811809
# This is because the ratelimiter limits already accounts for this.
812810
await self._ratelimiter.block()
813811

@@ -829,7 +827,7 @@ async def __identify(
829827
self.__shard = shard
830828
self.__presence = presence
831829
payload: dict = {
832-
"op": OpCodeType.IDENTIFY,
830+
"op": OpCodeType.IDENTIFY.value,
833831
"d": {
834832
"token": self._http.token,
835833
"intents": self._intents.value,
@@ -853,7 +851,7 @@ async def __identify(
853851
async def __resume(self) -> None:
854852
"""Sends a ``RESUME`` packet to the gateway."""
855853
payload: dict = {
856-
"op": OpCodeType.RESUME,
854+
"op": OpCodeType.RESUME.value,
857855
"d": {"token": self._http.token, "seq": self.sequence, "session_id": self.session_id},
858856
}
859857
log.debug(f"RESUMING: {payload}")
@@ -862,7 +860,7 @@ async def __resume(self) -> None:
862860

863861
async def __heartbeat(self) -> None:
864862
"""Sends a ``HEARTBEAT`` packet to the gateway."""
865-
payload: dict = {"op": OpCodeType.HEARTBEAT, "d": self.sequence}
863+
payload: dict = {"op": OpCodeType.HEARTBEAT.value, "d": self.sequence}
866864
await self._send_packet(payload)
867865
log.debug("HEARTBEAT")
868866

@@ -888,7 +886,7 @@ async def _update_presence(self, presence: ClientPresence) -> None:
888886
:param presence: The presence to change the bot to on identify.
889887
:type presence: ClientPresence
890888
"""
891-
payload: dict = {"op": OpCodeType.PRESENCE, "d": presence._json}
889+
payload: dict = {"op": OpCodeType.PRESENCE.value, "d": presence._json}
892890
await self._send_packet(payload)
893891
log.debug(f"UPDATE_PRESENCE: {presence._json}")
894892
self.__presence = presence

interactions/api/models/presence.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,6 @@ def __attrs_post_init__(self):
181181
# If since is not provided by the developer...
182182
self.since = int(time.time() * 1000) if self.status == "idle" else 0
183183
self._json["since"] = self.since
184+
if not self._json.get("afk"):
185+
self.afk = False
186+
self._json["afk"] = False

0 commit comments

Comments
 (0)