Skip to content

Commit

Permalink
Allow for channel caching in guilds if the channel object already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
4Kaylum committed Sep 10, 2023
1 parent 0cdca6d commit a61a244
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions novus/models/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,22 +2031,26 @@ def _add_voice_state(

def _add_channel(
self,
channel: payloads.Channel,
channel: payloads.Channel | Channel,
new_cache: dict[int, Any] | None = None) -> Channel:
"""
Add a channel to the guild's cache, updating the state cache at the same
time.
"""

cached = self.state.cache.get_channel(channel["id"])
if cached:
created = cached._update(channel)
if isinstance(channel, dict):
cached = self.state.cache.get_channel(channel["id"])
if cached:
created = cached._update(channel)
else:
created = Channel(
state=self.state,
data=channel,
guild_id=self.id,
)
else:
created = channel
else:
created = Channel(
state=self.state,
data=channel,
guild_id=self.id,
)
self.state.cache.add_channels(created)
(new_cache or self._channels)[created.id] = created
return created
Expand Down

0 comments on commit a61a244

Please sign in to comment.