-
Notifications
You must be signed in to change notification settings - Fork 140
feat(emoji)!: implement app emojis #1224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Snipy7374
wants to merge
23
commits into
DisnakeDev:master
Choose a base branch
from
Snipy7374:feat/app_emojis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−11
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6ef3bc0
implement app emojis
Snipy7374 cae204a
add changelog file
Snipy7374 ca00391
update docs
Snipy7374 c1f492a
Merge branch 'master' into feat/app_emojis
Snipy7374 18a127b
Merge branch 'master' into feat/app_emojis
Snipy7374 710c40f
edit Emoji to represent app emojis
Snipy7374 d405d7f
fix docs
Snipy7374 d397f8d
don't store application id in emoji
Snipy7374 37f218d
update slots
Snipy7374 51dae3b
Update disnake/client.py
Snipy7374 b2d343a
Update disnake/client.py
Snipy7374 9cba32c
Update disnake/emoji.py
Snipy7374 3b3cbb9
Update disnake/emoji.py
Snipy7374 8247fa3
Update disnake/emoji.py
Snipy7374 e38bda8
Update disnake/client.py
Snipy7374 74bdc75
Update disnake/emoji.py
Snipy7374 0e7ad20
Merge branch 'master' into feat/app_emojis
Snipy7374 2d94bc5
Merge branch 'master' into feat/app_emojis
Snipy7374 3c5a6ef
remove caching capabilities for app emojis
Snipy7374 4170cba
bump versions, add is_app_emoji property and fix docs
Snipy7374 47aec98
update changelog entry
Snipy7374 4b9cef8
add breaking change notice
Snipy7374 fc3276a
make properties use guild_id attribute instead of calling other 2 fun…
Snipy7374 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
:attr:`Emoji.guild_id` can now be ``None`` is the emoji is owned by an application. You can use :meth:`Emoji.is_app_emoji` to check for that. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Edit :class:`.Emoji` to represent application emojis. | ||
Add new methods and properties on :class:`Client` to fetch and create application emojis: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -51,6 +51,10 @@ class Emoji(_EmojiTag, AssetMixin): | |||||||||
|
||||||||||
Returns the emoji rendered for Discord. | ||||||||||
|
||||||||||
.. versionchanged:: 2.11 | ||||||||||
|
||||||||||
This class can now represents app emojis too. You can use :meth:`Emoji.is_app_emoji` to check for this. | ||||||||||
|
||||||||||
Attributes | ||||||||||
---------- | ||||||||||
name: :class:`str` | ||||||||||
|
@@ -63,8 +67,8 @@ class Emoji(_EmojiTag, AssetMixin): | |||||||||
Whether the emoji is animated or not. | ||||||||||
managed: :class:`bool` | ||||||||||
Whether the emoji is managed by a Twitch integration. | ||||||||||
guild_id: :class:`int` | ||||||||||
The guild ID the emoji belongs to. | ||||||||||
guild_id: Optional[:class:`int`] | ||||||||||
The guild ID the emoji belongs to. ``None`` if this is an app emoji. | ||||||||||
available: :class:`bool` | ||||||||||
Whether the emoji is available for use. | ||||||||||
user: Optional[:class:`User`] | ||||||||||
|
@@ -86,9 +90,13 @@ class Emoji(_EmojiTag, AssetMixin): | |||||||||
) | ||||||||||
|
||||||||||
def __init__( | ||||||||||
self, *, guild: Union[Guild, GuildPreview], state: ConnectionState, data: EmojiPayload | ||||||||||
self, | ||||||||||
*, | ||||||||||
guild: Optional[Union[Guild, GuildPreview]], | ||||||||||
state: ConnectionState, | ||||||||||
data: EmojiPayload, | ||||||||||
) -> None: | ||||||||||
self.guild_id: int = guild.id | ||||||||||
self.guild_id: Optional[int] = guild.id if guild else None | ||||||||||
self._state: ConnectionState = state | ||||||||||
self._from_data(data) | ||||||||||
|
||||||||||
|
@@ -151,16 +159,42 @@ def roles(self) -> List[Role]: | |||||||||
and count towards a separate limit of 25 emojis. | ||||||||||
""" | ||||||||||
guild = self.guild | ||||||||||
if guild is None: # pyright: ignore[reportUnnecessaryComparison] | ||||||||||
if guild is None: | ||||||||||
return [] | ||||||||||
|
||||||||||
return [role for role in guild.roles if self._roles.has(role.id)] | ||||||||||
|
||||||||||
@property | ||||||||||
def guild(self) -> Guild: | ||||||||||
""":class:`Guild`: The guild this emoji belongs to.""" | ||||||||||
def guild(self) -> Optional[Guild]: | ||||||||||
"""Optional[:class:`Guild`]: The guild this emoji belongs to. ``None`` if this is an app emoji. | ||||||||||
|
||||||||||
.. versionchanged:: 2.11 | ||||||||||
|
||||||||||
This can now return ``None`` if the emoji is an | ||||||||||
application owned emoji. | ||||||||||
""" | ||||||||||
# this will most likely never return None but there's a possibility | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment is no longer saying anything useful, remove it perhaps? |
||||||||||
return self._state._get_guild(self.guild_id) # type: ignore | ||||||||||
return self._state._get_guild(self.guild_id) | ||||||||||
|
||||||||||
@property | ||||||||||
def application_id(self) -> Optional[int]: | ||||||||||
"""Optional[:class:`int`]: The ID of the application which owns this emoji. | ||||||||||
|
||||||||||
.. versionadded:: 2.11 | ||||||||||
""" | ||||||||||
if self.guild_id is None: | ||||||||||
return None | ||||||||||
return self._state.application_id | ||||||||||
|
||||||||||
@property | ||||||||||
def is_app_emoji(self) -> bool: | ||||||||||
""":class:`bool`: Whether this is an application emoji. | ||||||||||
|
||||||||||
.. versionadded:: 2.11 | ||||||||||
""" | ||||||||||
if self.guild_id is None: | ||||||||||
return True | ||||||||||
return False | ||||||||||
Comment on lines
+195
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
def is_usable(self) -> bool: | ||||||||||
"""Whether the bot can use this emoji. | ||||||||||
|
@@ -173,6 +207,8 @@ def is_usable(self) -> bool: | |||||||||
return False | ||||||||||
if not self._roles: | ||||||||||
return True | ||||||||||
if not self.guild: | ||||||||||
return self.available | ||||||||||
emoji_roles, my_roles = self._roles, self.guild.me._roles | ||||||||||
return any(my_roles.has(role_id) for role_id in emoji_roles) | ||||||||||
|
||||||||||
|
@@ -196,6 +232,13 @@ async def delete(self, *, reason: Optional[str] = None) -> None: | |||||||||
HTTPException | ||||||||||
An error occurred deleting the emoji. | ||||||||||
""" | ||||||||||
# this is an app emoji | ||||||||||
if self.guild is None: | ||||||||||
if self.application_id is None: | ||||||||||
# should never happen | ||||||||||
raise ValueError("This may be a library bug! Open an issue on GitHub.") | ||||||||||
|
||||||||||
return await self._state.http.delete_app_emoji(self.application_id, self.id) | ||||||||||
await self._state.http.delete_custom_emoji(self.guild.id, self.id, reason=reason) | ||||||||||
|
||||||||||
async def edit( | ||||||||||
|
@@ -242,7 +285,14 @@ async def edit( | |||||||||
if roles is not MISSING: | ||||||||||
payload["roles"] = [role.id for role in roles] | ||||||||||
|
||||||||||
data = await self._state.http.edit_custom_emoji( | ||||||||||
self.guild.id, self.id, payload=payload, reason=reason | ||||||||||
) | ||||||||||
if self.guild is None: | ||||||||||
if self.application_id is None: | ||||||||||
# should never happen | ||||||||||
raise ValueError("This may be a library bug! Open an issue on GitHub.") | ||||||||||
|
||||||||||
data = await self._state.http.edit_app_emoji(self.application_id, self.id, name) | ||||||||||
else: | ||||||||||
data = await self._state.http.edit_custom_emoji( | ||||||||||
self.guild.id, self.id, payload=payload, reason=reason | ||||||||||
) | ||||||||||
return Emoji(guild=self.guild, data=data, state=self._state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.