From e1da3ee781fe1e835777b6dcb40ff42a352fa385 Mon Sep 17 00:00:00 2001 From: ths_dev <61903983+TheMisterSenpai@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:43:02 +0300 Subject: [PATCH] feat(guild): add list and get emoji --- .github/FUNDING.yml | 2 +- melisa/models/guild/guild.py | 45 +++++++++++++++++++++++++++ melisa/rest.py | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 22dea67..28bb024 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -10,4 +10,4 @@ liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -custom: ['https://pay.cloudtips.ru/p/41f54886'] +custom: ['https://pay.cloudtips.ru/p/41f54886', 'https://sobe.ru/na/makaroni'] diff --git a/melisa/models/guild/guild.py b/melisa/models/guild/guild.py index 1b46993..d4e81b4 100644 --- a/melisa/models/guild/guild.py +++ b/melisa/models/guild/guild.py @@ -24,6 +24,7 @@ from ...utils.types import APINullable if TYPE_CHECKING: from .channel import ChannelType, Channel + from .emoji import Emoji class DefaultMessageNotificationLevel(IntEnum): @@ -619,6 +620,50 @@ class Guild(APIModelBase): """ await self._client.rest.remove_guild_ban(self.id, user_id, reason=reason) + + async def emojis( + self + ): + """|coro| + + Getting all emojis from guild + + 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.list_guild_emojis(self.id) + + async def emoji( + self, + emoji_id: Union[Snowflake, str, int] + ): + """|coro| + + Getting all emojis from guild + + Parameters + ---------- + emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + The ID of the emoji that we will get + + 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.get_guild_emoji(self.id, emoji_id) @dataclass(repr=False) diff --git a/melisa/rest.py b/melisa/rest.py index 49cb04c..553cd56 100644 --- a/melisa/rest.py +++ b/melisa/rest.py @@ -666,6 +666,65 @@ class RESTApp: headers={"X-Audit-Log-Reason": reason}, ) + async def list_guild_emojis( + self, + guild_id: Union[Snowflake, str, int], + ): + """|coro| + + [**REST API**] Getting all emojis from guild + + Parameters + ---------- + guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + ID of the guild in which we will get the list emojis + + 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._http.get( + f"/guilds/{guild_id}/emojis" + ) + + async def get_guild_emoji( + self, + guild_id: Union[Snowflake, str, int], + emoji_id: Union[Snowflake, str, int] + ): + """|coro| + + [**REST API**] Getting all emojis from guild + + Parameters + ---------- + guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + The ID of the guild in which we will receive emojis + emoji_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + The ID of the emoji that we will get + + 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.get( + f"/guilds/{guild_id}/emojis/{emoji_id}" + ) + + #TODO: add create and delete emoji + async def get_global_application_commands( self, application_id: Union[int, str, Snowflake],