From a61a2441746751428ad644388146dcf48c9a4a2e Mon Sep 17 00:00:00 2001 From: Kae Bartlett Date: Sun, 10 Sep 2023 23:37:44 +0100 Subject: [PATCH] Allow for channel caching in guilds if the channel object already exists --- novus/models/guild.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/novus/models/guild.py b/novus/models/guild.py index 66eadbbc..a77c2366 100644 --- a/novus/models/guild.py +++ b/novus/models/guild.py @@ -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