Skip to content

Commit e4cbb1c

Browse files
authored
feat: add info from guilds to cache (#912)
* feat: add info from guilds to cache * fix: transform Threads into Channels as needed * fix: you know what? let's just not. Threads may be updated when Channels aren't and vice versa. I'd rather not confuse things here.
1 parent 44c14ce commit e4cbb1c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

interactions/api/models/guild.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,19 @@ class Guild(ClientSerializerMixin, IDMixin):
331331

332332
# todo assign the correct type
333333

334+
def __attrs_post_init__(self): # sourcery skip: last-if-guard
335+
if self._client:
336+
# update the cache to include info found from guilds
337+
# these values wouldn't be "found out" until an update for them happened otherwise
338+
if self.channels:
339+
self._client.cache[Channel].update({c.id: c for c in self.channels})
340+
if self.threads:
341+
self._client.cache[Thread].update({t.id: t for t in self.threads})
342+
if self.roles:
343+
self._client.cache[Role].update({r.id: r for r in self.roles})
344+
if self.members:
345+
self._client.cache[Member].update({(self.id, m.id): m for m in self.members})
346+
334347
def __repr__(self) -> str:
335348
return self.name
336349

0 commit comments

Comments
 (0)