Browse Source

Remove cached emoji and sticker data if intent is disabled

pull/9499/head
Rapptz 2 years ago
parent
commit
5eeeef02e4
  1. 22
      discord/guild.py
  2. 7
      discord/state.py

22
discord/guild.py

@ -472,9 +472,15 @@ class Guild(Hashable):
role = Role(guild=self, data=r, state=state)
self._roles[role.id] = role
self.emojis: Tuple[Emoji, ...] = tuple(map(lambda d: state.store_emoji(self, d), guild.get('emojis', [])))
self.stickers: Tuple[GuildSticker, ...] = tuple(
map(lambda d: state.store_sticker(self, d), guild.get('stickers', []))
self.emojis: Tuple[Emoji, ...] = (
tuple(map(lambda d: state.store_emoji(self, d), guild.get('emojis', [])))
if state.cache_guild_expressions
else ()
)
self.stickers: Tuple[GuildSticker, ...] = (
tuple(map(lambda d: state.store_sticker(self, d), guild.get('stickers', [])))
if state.cache_guild_expressions
else ()
)
self.features: List[GuildFeature] = guild.get('features', [])
self._splash: Optional[str] = guild.get('splash')
@ -2898,7 +2904,10 @@ class Guild(Hashable):
payload['tags'] = emoji
data = await self._state.http.create_guild_sticker(self.id, payload, file, reason)
return self._state.store_sticker(self, data)
if self._state.cache_guild_expressions:
return self._state.store_sticker(self, data)
else:
return GuildSticker(state=self._state, data=data)
async def delete_sticker(self, sticker: Snowflake, /, *, reason: Optional[str] = None) -> None:
"""|coro|
@ -3307,7 +3316,10 @@ class Guild(Hashable):
role_ids = []
data = await self._state.http.create_custom_emoji(self.id, name, img, roles=role_ids, reason=reason)
return self._state.store_emoji(self, data)
if self._state.cache_guild_expressions:
return self._state.store_emoji(self, data)
else:
return Emoji(guild=self, state=self._state, data=data)
async def delete_emoji(self, emoji: Snowflake, /, *, reason: Optional[str] = None) -> None:
"""|coro|

7
discord/state.py

@ -259,6 +259,13 @@ class ConnectionState(Generic[ClientT]):
self.clear()
# For some reason Discord still sends emoji/sticker data in payloads
# This makes it hard to actually swap out the appropriate store methods
# So this is checked instead, it's a small penalty to pay
@property
def cache_guild_expressions(self) -> bool:
return self._intents.emojis_and_stickers
async def close(self) -> None:
for voice in self.voice_clients:
try:

Loading…
Cancel
Save