Skip to content

Commit 6cc7648

Browse files
ItsRqtlDamego
andauthored
feat: implement modify guild emoji helper (#1202)
* feat: implement modify guild emoji helper * you didn't see that * hmm * add http client * Update interactions/api/models/guild.py Co-authored-by: Damego <damego.dev@gmail.com> * Update interactions/api/models/guild.py Co-authored-by: Damego <damego.dev@gmail.com> * Update interactions/api/models/guild.py * feat: also implement helper in emoji model * Update interactions/api/models/emoji.py Co-authored-by: Damego <damego.dev@gmail.com> Co-authored-by: Damego <damego.dev@gmail.com>
1 parent 7982ace commit 6cc7648

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

interactions/api/models/emoji.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from typing import TYPE_CHECKING, List, Optional, Union
33

44
from ...utils.attrs_utils import ClientSerializerMixin, convert_list, define, field
5+
from ...utils.missing import MISSING
56
from ..error import LibraryException
67
from .misc import Snowflake
8+
from .role import Role
79
from .user import User
810

911
if TYPE_CHECKING:
@@ -109,6 +111,46 @@ async def get_all_of_guild(
109111
res = await client.get_all_emoji(guild_id=_guild_id)
110112
return [cls(**emoji, _client=client) for emoji in res]
111113

114+
async def modify(
115+
self,
116+
guild_id: Union[int, Snowflake, "Guild"],
117+
name: Optional[str] = MISSING,
118+
roles: Optional[Union[List[Role], List[int]]] = MISSING,
119+
reason: Optional[str] = None,
120+
) -> "Emoji":
121+
"""
122+
.. versionadded:: 4.4.0
123+
124+
Edits the Emoji in a guild.
125+
126+
:param int guild_id: The id of the guild to edit the emoji on
127+
:param Optional[str] name: The name of the emoji. If not specified, the filename will be used
128+
:param Optional[Union[List[Role], List[int]]] roles: Roles allowed to use this emoji
129+
:param Optional[str] reason: The reason of the modification
130+
:return: The modified emoji object
131+
:rtype: Emoji
132+
"""
133+
if not self._client:
134+
raise LibraryException(code=13)
135+
136+
payload: dict = {}
137+
138+
if name is not MISSING:
139+
payload["name"] = name
140+
141+
if roles is not MISSING:
142+
payload["roles"] = [int(role.id if isinstance(role, Role) else role) for role in roles]
143+
144+
_guild_id = int(guild_id) if isinstance(guild_id, (int, Snowflake)) else int(guild_id.id)
145+
146+
res = await self._client.modify_guild_emoji(
147+
guild_id=_guild_id, emoji_id=int(self.id), payload=payload, reason=reason
148+
)
149+
150+
self.update(res)
151+
152+
return self
153+
112154
async def delete(
113155
self,
114156
guild_id: Union[int, Snowflake, "Guild"],

interactions/api/models/guild.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,53 @@ async def create_emoji(
22382238
self.emojis.append(_emoji)
22392239
return _emoji
22402240

2241+
async def modify_emoji(
2242+
self,
2243+
emoji_id: Union[int, Snowflake, Emoji],
2244+
name: Optional[str] = MISSING,
2245+
roles: Optional[Union[List[Role], List[int]]] = MISSING,
2246+
reason: Optional[str] = None,
2247+
) -> Emoji:
2248+
"""
2249+
.. versionadded:: 4.4.0
2250+
2251+
Edits an Emoji in the guild.
2252+
2253+
:param Union[int, Snowflake, Emoji] emoji_id: The id of the emoji to edit
2254+
:param Optional[str] name: The name of the emoji. If not specified, the filename will be used
2255+
:param Optional[Union[List[Role], List[int]]] roles: Roles allowed to use this emoji
2256+
:param Optional[str] reason: The reason of the modification
2257+
:return: The modified emoji object
2258+
:rtype: Emoji
2259+
"""
2260+
if not self._client:
2261+
raise LibraryException(code=13)
2262+
2263+
emoji_id = int(emoji_id.id if isinstance(emoji_id, Emoji) else emoji_id)
2264+
2265+
payload: dict = {}
2266+
2267+
if name is not MISSING:
2268+
payload["name"] = name
2269+
2270+
if roles is not MISSING:
2271+
payload["roles"] = [int(role.id if isinstance(role, Role) else role) for role in roles]
2272+
2273+
res = await self._client.modify_guild_emoji(
2274+
guild_id=int(self.id), emoji_id=emoji_id, payload=payload, reason=reason
2275+
)
2276+
2277+
_emoji = Emoji(**res, _client=self._client)
2278+
if self.emojis is None:
2279+
self.emojis = []
2280+
for index, item in enumerate(self.emojis):
2281+
if item.id == emoji_id:
2282+
self.roles[index] = _emoji
2283+
break
2284+
else:
2285+
self.roles.append(_emoji)
2286+
return _emoji
2287+
22412288
async def delete_emoji(
22422289
self,
22432290
emoji: Union[Emoji, int],

0 commit comments

Comments
 (0)