feat(guild): support emojis

This commit is contained in:
ths_dev 2022-06-30 21:48:40 +03:00
parent 45373e1f99
commit 17c16279b1
2 changed files with 245 additions and 5 deletions

View file

@ -306,7 +306,6 @@ class Guild(APIModelBase):
id: Snowflake id: Snowflake
roles: APINullable[Dict] roles: APINullable[Dict]
emojis: APINullable[Dict]
members: APINullable[Dict] members: APINullable[Dict]
threads: APINullable[Dict] threads: APINullable[Dict]
presences: APINullable[Dict] presences: APINullable[Dict]
@ -328,6 +327,7 @@ class Guild(APIModelBase):
default_message_notifications: APINullable[int] = None default_message_notifications: APINullable[int] = None
explicit_content_filter: APINullable[int] = None explicit_content_filter: APINullable[int] = None
features: APINullable[List[str]] = None features: APINullable[List[str]] = None
emojis: APINullable[Emoji] = None
# TODO: Make a structures of emoji and role # TODO: Make a structures of emoji and role
mfa_level: APINullable[MFALevel] = None mfa_level: APINullable[MFALevel] = None
@ -646,7 +646,7 @@ class Guild(APIModelBase):
): ):
"""|coro| """|coro|
Getting all emojis from guild Get emoji from guild
Parameters Parameters
---------- ----------
@ -665,6 +665,115 @@ class Guild(APIModelBase):
await self._client.rest.get_guild_emoji(self.id, emoji_id) await self._client.rest.get_guild_emoji(self.id, emoji_id)
async def create_emoji(
self,
emoji_name: Optional[str],
emoji_image: Optional[str],
*,
reason: Optional[str] = None,
role_id: Union[Snowflake, str, int] = None
):
"""|coro|
Create a new emoji for the guild.
Requires the `MANAGE_EMOJIS_AND_STICKERS` permission.
Returns the new emoji object on success. Fires a Guild Emojis Update Gateway event.
Parameters
----------
emoji_name: Optional[:class:`str`]
Name of the emoji
emoji_image: Optional[:class:`str`]
The 128x128 emoji image
reason: Optional[:class:`str`]
The reason of the action
role_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Roles allowed to use this emoji
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild
"""
await self._client.rest.create_guild_emoji(self.id, emoji_name, emoji_image, reason=reason, role_id=role_id)
async def edit_emoji(
self,
emoji_id: Union[Snowflake, str, int],
emoji_name: Optional[str],
*,
reason: Optional[str] = None,
role_id: Union[Snowflake, str, int] = None
):
"""|coro|
Modify the given emoji.
Requires the `MANAGE_EMOJIS_AND_STICKERS` permission.
Returns the updated emoji object on success. Fires a Guild Emojis Update Gateway event.
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
ID of the guild in which we will modify emoji
emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the emoji that we will modify
emoji_name: Optional[:class:`str`]
Name of the emoji
reason: Optional[:class:`str`]
The reason of the action
role_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Roles allowed to use this emoji
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild and emoji
"""
await self._client.rest.modify_guild_emoji(self.id, emoji_id, emoji_name, reason=reason, role_id=role_id)
async def delete_emoji(
self,
emoji_id: Union[Snowflake, str, int],
*,
reason: Optional[str] = None
):
"""|coro|
Delete the given emoji.
Requires the `MANAGE_EMOJIS_AND_STICKERS` permission.
Returns `204 No Content` on success. Fires a Guild Emojis Update Gateway event.
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
ID of the guild in which we will delete emoji
emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the emoji that we will delete
reason: Optional[:class:`str`]
The reason of the action
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild and emoji
"""
await self._client.rest.delete_guild_emoji(self.id, emoji_id, reason=reason)
@dataclass(repr=False) @dataclass(repr=False)
class UnavailableGuild(APIModelBase): class UnavailableGuild(APIModelBase):

View file

@ -700,12 +700,12 @@ class RESTApp:
): ):
"""|coro| """|coro|
[**REST API**] Getting all emojis from guild [**REST API**] Get emoji from guild
Parameters Parameters
---------- ----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the guild in which we will receive emojis The ID of the guild in which we will receive emoji
emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the emoji that we will get The ID of the emoji that we will get
@ -723,7 +723,138 @@ class RESTApp:
f"/guilds/{guild_id}/emojis/{emoji_id}" f"/guilds/{guild_id}/emojis/{emoji_id}"
) )
#TODO: add create and delete emoji async def create_guild_emoji(
self,
guild_id: Union[int, str, Snowflake],
emoji_name: Optional[str],
emoji_image: Optional[str],
*,
reason: Optional[str] = None,
role_id: Union[int, str, Snowflake] = None
):
"""|coro|
[**REST API**] Create a new emoji for the guild.
**Required permissions:** ``MANAGE_EMOJIS_AND_STICKERS``.
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
ID of the guild in which we will create emoji
emoji_name: Optional[:class:`str`]
Name of the emoji
emoji_image: Optional[:class:`str`]
The 128x128 emoji image
reason: Optional[:class:`str`]
The reason of the action
role_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Roles allowed to use this emoji
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild
"""
data = {
"name": emoji_name,
"image": emoji_image,
"roles": role_id
}
await self._http.post(
f"/guilds/{guild_id}/emojis",
json = data,
headers={"X-Audit-Log-Reason": reason}
)
async def modify_guild_emoji(
self,
guild_id: Union[int, str, Snowflake],
emoji_id: Union[int, str, Snowflake],
emoji_name: Optional[str],
*,
reason: Optional[str] = None,
role_id: Union[int, str, Snowflake] = None
):
"""|coro|
[**REST API**] Modify the given emoji.
**Required permissions:** ``MANAGE_EMOJIS_AND_STICKERS``.
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
ID of the guild in which we will modify emoji
emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the emoji that we will modify
emoji_name: Optional[:class:`str`]
Name of the emoji
reason: Optional[:class:`str`]
The reason of the action
role_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
Roles allowed to use this emoji
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild and emoji
"""
data = {
"name": emoji_name,
"roles": role_id
}
await self._http.patch(
f"/guilds/{guild_id}/emojis/{emoji_id}",
json = data,
headers={"X-Audit-Log-Reason": reason}
)
async def delete_guild_emoji(
self,
guild_id: Union[int, str, Snowflake],
emoji_id: Union[int, str, Snowflake],
*,
reason: Optional[str] = None
):
"""|coro|
[**REST API**] Delete the given emoji
**Required permissions:** ``MANAGE_EMOJIS_AND_STICKERS``.
Parameters
----------
guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
ID of the guild in which we will delete emoji
emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`]
The ID of the emoji that we will delete
reason: Optional[:class:`str`]
The reason of the action
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong guild and emoji
"""
await self._http.delete(
f"/guilds/{guild_id}/emojis/{emoji_id}",
headers={"X-Audit-Log-Reason": reason}
)
async def get_global_application_commands( async def get_global_application_commands(
self, self,