fix: Implement cache safeguard on some requests that require ID checking.
This is in response to
@@ -432,6 +432,7 @@ class HTTPClient:
request = await self._req.request(
Route("POST", "/channels/{channel_id}/messages", channel_id=channel_id), json=payload
)
+ if request.get("id"):
self.cache.messages.add(Item(id=request["id"], value=Message(**request)))
return request
@@ -536,6 +537,7 @@ class HTTPClient:
request = await self._req.request(Route("GET", "/users/@me/guilds"))
for guild in request:
+ if guild.get("id"):
self.cache.self_guilds.add(Item(id=guild["id"], value=Guild(**guild)))
return request
@@ -863,6 +865,7 @@ class HTTPClient:
)
for channel in request:
+ if channel.get("id"):
self.cache.channels.add(Item(id=channel["id"], value=Channel(**channel)))
return request
@@ -878,6 +881,7 @@ class HTTPClient:
)
for role in request:
+ if role.get("id"):
self.cache.roles.add(Item(id=role["id"], value=Role(**role)))
return request
@@ -895,6 +899,7 @@ class HTTPClient:
request = await self._req.request(
Route("POST", f"/guilds/{guild_id}/roles"), json=data, reason=reason
)
+ if request.get("id"):
self.cache.roles.add(Item(id=request["id"], value=Role(**request)))
return request
@@ -1269,6 +1274,7 @@ class HTTPClient:
)
for message in request:
+ if message.get("id"):
self.cache.messages.add(Item(id=message["id"], value=Message(**message)))
return request
@@ -1290,6 +1296,7 @@ class HTTPClient:
request = await self._req.request(
Route("POST", f"/guilds/{guild_id}/channels"), json=payload, reason=reason
)
+ if request.get("id"):
self.cache.channels.add(Item(id=request["id"], value=Channel(**request)))
return request
@@ -1651,6 +1658,7 @@ class HTTPClient:
json=payload,
reason=reason,
)
+ if request.get("id"):
self.cache.channels.add(Item(id=request["id"], value=request))
return request
@@ -1659,6 +1667,7 @@ class HTTPClient:
request = await self._req.request(
Route("POST", f"/channels/{channel_id}/threads"), json=payload, reason=reason
)
+ if request.get("id"):
self.cache.channels.add(Item(id=request["id"], value=request))
return request
