Skip to content

Commit

Permalink
fix: adjust app emoji code based off testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS committed Jan 2, 2025
1 parent b798fbe commit 54258f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion interactions/client/smart_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def get_emoji(self, emoji_id: Optional["Snowflake_Type"]) -> Optional["CustomEmo
"""
return self.emoji_cache.get(to_optional_snowflake(emoji_id)) if self.emoji_cache is not None else None

def place_emoji_data(self, guild_id: "Snowflake_Type", data: discord_typings.EmojiData) -> "CustomEmoji":
def place_emoji_data(self, guild_id: "Snowflake_Type | None", data: discord_typings.EmojiData) -> "CustomEmoji":
"""
Take json data representing an emoji, process it, and cache it. This cache is disabled by default, start your bot with `Client(enable_emoji_cache=True)` to enable it.
Expand Down
28 changes: 14 additions & 14 deletions interactions/models/discord/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from interactions.client.utils.attr_converters import optional
from interactions.client.utils.serializer import to_image_data
from interactions.models.discord.asset import Asset
from interactions.models.discord.emoji import PartialEmoji
from interactions.models.discord.emoji import CustomEmoji
from interactions.models.discord.enums import ApplicationFlags
from interactions.models.discord.file import UPLOADABLE_TYPE
from interactions.models.discord.snowflake import Snowflake_Type, to_snowflake
Expand Down Expand Up @@ -92,34 +92,34 @@ def owner(self) -> "User":
"""The user object for the owner of this application"""
return self._client.cache.get_user(self.owner_id)

async def fetch_all_emoji(self) -> List[PartialEmoji]:
async def fetch_all_emoji(self) -> List[CustomEmoji]:
"""Fetch all emojis for this application"""
response = await self._client.http.get_application_emojis(self.id)
return [self._client.cache.place_emoji_data(None, emoji) for emoji in response]
response = await self.client.http.get_application_emojis(self.id)
return [self.client.cache.place_emoji_data(None, emoji) for emoji in response]

async def fetch_emoji(self, emoji_id: Snowflake_Type) -> PartialEmoji:
async def fetch_emoji(self, emoji_id: Snowflake_Type) -> CustomEmoji:
"""Fetch an emoji for this application"""
response = await self._client.http.get_application_emoji(self.id, emoji_id)
return await self._client.cache.place_emoji_data(None, response)
response = await self.client.http.get_application_emoji(self.id, emoji_id)
return self.client.cache.place_emoji_data(None, response)

async def create_emoji(self, name: str, imagefile: UPLOADABLE_TYPE) -> PartialEmoji:
async def create_emoji(self, name: str, imagefile: UPLOADABLE_TYPE) -> CustomEmoji:
"""Create an emoji for this application"""
data_payload = {
"name": name,
"image": to_image_data(imagefile),
"roles": MISSING,
}

return self._client.cache.place_emoji_data(
None, await self._client.http.create_application_emoji(data_payload, self.id)
return self.client.cache.place_emoji_data(
None, await self.client.http.create_application_emoji(data_payload, self.id)
)

async def edit_emoji(self, emoji_id: Snowflake_Type, name: str) -> PartialEmoji:
async def edit_emoji(self, emoji_id: Snowflake_Type, name: str) -> CustomEmoji:
"""Edit an emoji for this application"""
return await self._client.cache.place_emoji_data(
None, self._client.http.edit_application_emoji(self.id, emoji_id, name)
return self.client.cache.place_emoji_data(
None, await self.client.http.edit_application_emoji(self.id, emoji_id, name)
)

async def delete_emoji(self, emoji_id: Snowflake_Type) -> None:
"""Delete an emoji for this application"""
return await self._client.http.delete_application_emoji(self.id, emoji_id)
await self.client.http.delete_application_emoji(self.id, emoji_id)
5 changes: 4 additions & 1 deletion interactions/models/discord/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]
return data

@classmethod
def from_dict(cls, data: Dict[str, Any], client: "Client", guild_id: int) -> "CustomEmoji":
def from_dict(cls, data: Dict[str, Any], client: "Client", guild_id: "Optional[Snowflake_Type]") -> "CustomEmoji":
data = cls._process_dict(data, client)
return cls(client=client, guild_id=guild_id, **cls._filter_kwargs(data, cls._get_init_keys()))

Expand Down Expand Up @@ -216,6 +216,9 @@ async def delete(self, reason: Optional[str] = None) -> None:
"""
if not self._guild_id:
if reason:
raise ValueError("Cannot specify reason for application emoji.")

await self.client.http.delete_application_emoji(self._client.app.id, self.id)
else:
await self._client.http.delete_guild_emoji(self._guild_id, self.id, reason=reason)
Expand Down

0 comments on commit 54258f6

Please sign in to comment.