Skip to content

Commit c66d0fe

Browse files
committed
refactor: split runtime changes into separate PR
1 parent 8e8e351 commit c66d0fe

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

changelog/1223.breaking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
:attr:`Emoji.guild_id` can now be ``None`` if the emoji is owned by an application. You can use :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji` to check if this is a Guild or App Emoji.
1+
:attr:`Emoji.guild_id` can now be ``None`` if the emoji is owned by an application. You can use :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji` to check if this is a Guild or App Emoji.

changelog/1223.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add support to :class:`.Emoji` to represent application-owned emojis.
22
- New methods on :class:`Client`: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`.
3-
- New attributes/methods on :class:`.Emoji`: :attr:`Emoji.application_id`, :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji`.
3+
- New attributes on :class:`.Emoji`: :attr:`Emoji.application_id`, :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji`.

changelog/1388.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add support to :class:`.Emoji` to represent application-owned emojis.
22
- New methods on :class:`Client`: :meth:`Client.fetch_application_emoji`, :meth:`Client.fetch_application_emojis` and :meth:`Client.create_application_emoji`.
3-
- New attributes/methods on :class:`.Emoji`: :attr:`Emoji.application_id`, :meth:`Emoji.is_guild_emoji` and :meth:`Emoji.is_app_emoji`.
3+
- New attributes on :class:`.Emoji`: :attr:`Emoji.application_id`, :attr:`Emoji.is_guild_emoji` and :attr:`Emoji.is_app_emoji`.

disnake/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ async def application_info(self) -> AppInfo:
24182418
data = await self.http.application_info()
24192419
return AppInfo(self._connection, data)
24202420

2421-
async def fetch_application_emoji(self, emoji_id: int, /) -> Emoji:
2421+
async def fetch_application_emoji(self, emoji_id: int) -> Emoji:
24222422
"""|coro|
24232423
24242424
Retrieves an application level :class:`~disnake.Emoji` based on its ID.
@@ -2477,7 +2477,7 @@ async def create_application_emoji(self, *, name: str, image: AssetBytes) -> Emo
24772477
The newly created application emoji.
24782478
"""
24792479
img = await utils._assetbytes_to_base64_data(image)
2480-
data = await self.http.create_app_emoji(self.application_id, name=name, image=img)
2480+
data = await self.http.create_app_emoji(self.application_id, name, img)
24812481
return Emoji(guild=None, state=self._connection, data=data)
24822482

24832483
async def fetch_application_emojis(self) -> List[Emoji]:

disnake/emoji.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Emoji(_EmojiTag, AssetMixin):
5454
5555
.. versionchanged:: |vnext|
5656
57-
This class can now represent app emojis. Use :meth:`Emoji.is_app_emoji` to check for this.
58-
To check if this is a guild emoji, use :meth:`Emoji.is_guild_emoji`.
57+
This class can now represent app emojis. Use :attr:`Emoji.is_app_emoji` to check for this.
58+
To check if this is a guild emoji, use :attr:`Emoji.is_guild_emoji`.
5959
6060
Attributes
6161
----------
@@ -196,21 +196,19 @@ def application_id(self) -> Optional[int]:
196196
return None
197197
return self._state.application_id
198198

199+
@property
199200
def is_guild_emoji(self) -> bool:
200-
"""Whether this emoji is a guild emoji.
201+
""":class:`bool`: Whether this emoji is a guild emoji.
201202
202203
.. versionadded:: |vnext|
203-
204-
:return type: :class:`bool`
205204
"""
206205
return self.guild_id is not None
207206

207+
@property
208208
def is_app_emoji(self) -> bool:
209-
"""Whether this emoji is an application emoji.
209+
""":class:`bool`: Whether this emoji is an application emoji.
210210
211211
.. versionadded:: |vnext|
212-
213-
:return type: :class:`bool`
214212
"""
215213
return self.guild_id is None
216214

@@ -223,8 +221,10 @@ def is_usable(self) -> bool:
223221
"""
224222
if not self.available:
225223
return False
226-
# if we don't have a guild, this is an app emoji
227-
if not self.guild or not self._roles:
224+
if not self.guild:
225+
# if we don't have a guild, this is an app emoji
226+
return self.available
227+
if not self._roles:
228228
return True
229229
emoji_roles, my_roles = self._roles, self.guild.me._roles
230230
return any(my_roles.has(role_id) for role_id in emoji_roles)
@@ -253,8 +253,8 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
253253
InvalidData
254254
The emoji data is invalid and cannot be processed.
255255
"""
256-
if self.guild_id is None:
257-
# this is an app emoji
256+
# this is an app emoji
257+
if self.guild is None:
258258
if self.application_id is None:
259259
# should never happen
260260
msg = (
@@ -264,7 +264,7 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
264264
raise InvalidData(msg)
265265

266266
return await self._state.http.delete_app_emoji(self.application_id, self.id)
267-
await self._state.http.delete_custom_emoji(self.guild_id, self.id, reason=reason)
267+
await self._state.http.delete_custom_emoji(self.guild.id, self.id, reason=reason)
268268

269269
async def edit(
270270
self, *, name: str = MISSING, roles: List[Snowflake] = MISSING, reason: Optional[str] = None
@@ -310,8 +310,13 @@ async def edit(
310310
:class:`Emoji`
311311
The newly updated emoji.
312312
"""
313-
if self.guild_id is None:
314-
# this is an app emoji
313+
payload = {}
314+
if name is not MISSING:
315+
payload["name"] = name
316+
if roles is not MISSING:
317+
payload["roles"] = [role.id for role in roles]
318+
319+
if self.guild is None:
315320
if self.application_id is None:
316321
# should never happen
317322
msg = (
@@ -320,15 +325,9 @@ async def edit(
320325
)
321326
raise InvalidData(msg)
322327

323-
data = await self._state.http.edit_app_emoji(self.application_id, self.id, name=name)
328+
data = await self._state.http.edit_app_emoji(self.application_id, self.id, name)
324329
else:
325-
payload = {}
326-
if name is not MISSING:
327-
payload["name"] = name
328-
if roles is not MISSING:
329-
payload["roles"] = [role.id for role in roles]
330-
331330
data = await self._state.http.edit_custom_emoji(
332-
self.guild_id, self.id, payload=payload, reason=reason
331+
self.guild.id, self.id, payload=payload, reason=reason
333332
)
334333
return Emoji(guild=self.guild, data=data, state=self._state)

disnake/http.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,7 @@ def get_custom_emoji(self, guild_id: Snowflake, emoji_id: Snowflake) -> Response
17711771
)
17721772
)
17731773

1774-
def create_app_emoji(
1775-
self, app_id: Snowflake, *, name: str, image: str
1776-
) -> Response[emoji.Emoji]:
1774+
def create_app_emoji(self, app_id: Snowflake, name: str, image: str) -> Response[emoji.Emoji]:
17771775
payload: Dict[str, Any] = {
17781776
"name": name,
17791777
"image": image,
@@ -1783,7 +1781,7 @@ def create_app_emoji(
17831781
return self.request(r, json=payload)
17841782

17851783
def edit_app_emoji(
1786-
self, app_id: Snowflake, emoji_id: Snowflake, *, name: str
1784+
self, app_id: Snowflake, emoji_id: Snowflake, name: str
17871785
) -> Response[emoji.Emoji]:
17881786
payload: Dict[str, Any] = {
17891787
"name": name,

0 commit comments

Comments
 (0)