From 076a8ccdf3ea239cc7d784765a5edfc63c2b0df6 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sun, 27 Mar 2022 17:03:46 +0300 Subject: [PATCH] update docs and channel delete --- docs/source/models/guild.rst | 46 +++++++++++++++++++++++++------ docs/source/models/user.rst | 1 + melisa/models/guild/__init__.py | 1 + melisa/models/guild/channel.py | 49 ++++++++++++++++++++++++++++++--- melisa/models/user/user.py | 4 --- 5 files changed, 85 insertions(+), 16 deletions(-) diff --git a/docs/source/models/guild.rst b/docs/source/models/guild.rst index 877b8a9..1c77995 100644 --- a/docs/source/models/guild.rst +++ b/docs/source/models/guild.rst @@ -3,16 +3,47 @@ Melisa Models Guild =========================== + +Channel +-------- + +ChannelType +~~~~~~~~~~~~~ + +.. autoclass:: ChannelType() + +VideoQualityModes +~~~~~~~~~~~~~~~~~~ + +.. autoclass:: VideoQualityModes() + +Channel +~~~~~~~ + +.. attributetable:: Channel + +.. autoclass:: Channel() + :inherited-members: + +TextChannel +~~~~~~~~~~~~~ + +.. attributetable:: TextChannel + +.. autoclass:: TextChannel() + :inherited-members: + + Guild ----- +------ DefaultMessageNotificationLevel -~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. autoclass:: DefaultMessageNotificationLevel() ExplicitContentFilterLevel -~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. autoclass:: ExplicitContentFilterLevel() @@ -22,7 +53,7 @@ MFALevel .. autoclass:: MFALevel() VerificationLevel -~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~ .. autoclass:: VerificationLevel() @@ -37,7 +68,7 @@ PremiumTier .. autoclass:: PremiumTier() SystemChannelFlags -~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~ .. autoclass:: SystemChannelFlags() @@ -48,14 +79,13 @@ GuildFeatures Guild ~~~~~ - .. attributetable:: Guild .. autoclass:: Guild() + :inherited-members: UnavailableGuild -~~~~~ - +~~~~~~~~~~~~~~~~ .. attributetable:: UnavailableGuild .. autoclass:: UnavailableGuild() diff --git a/docs/source/models/user.rst b/docs/source/models/user.rst index c9cf9df..67a5bbb 100644 --- a/docs/source/models/user.rst +++ b/docs/source/models/user.rst @@ -27,4 +27,5 @@ User .. attributetable:: User .. autoclass:: User() + :inherited-members: diff --git a/melisa/models/guild/__init__.py b/melisa/models/guild/__init__.py index f7b956f..758e6f1 100644 --- a/melisa/models/guild/__init__.py +++ b/melisa/models/guild/__init__.py @@ -2,3 +2,4 @@ # Full MIT License can be found in `LICENSE.txt` at the project root. from .guild import * +from .channel import * diff --git a/melisa/models/guild/channel.py b/melisa/models/guild/channel.py index bbedb4b..28a24d8 100644 --- a/melisa/models/guild/channel.py +++ b/melisa/models/guild/channel.py @@ -34,7 +34,7 @@ class ChannelType(IntEnum): GUILD_STORE: A channel in which game developers can sell their game on Discord GUILD_NEWS_THREAD: - A temporary sub-channel within a `GUILD_NEWS` channel + A temporary sub-channel within a **GUILD_NEWS** channel GUILD_PUBLIC_THREAD: A temporary sub-channel within a GUILD_TEXT channel GUILD_PRIVATE_THREAD: @@ -115,6 +115,42 @@ class Channel(APIModelBase): def mention(self): return f"<#{self.id}>" + async def delete( + self, + *, + reason: Optional[str] = None + ) -> Dict[str, Any]: + """|coro| + + Delete a channel, or close a private message. + Deleting a category does not delete its child channels; + they will have their parent_id removed. + + Parameters + ---------- + reason: Optional[:class:`str`] + The reason of the delete channel operation. + + Raises + ------- + NotFoundError + If channel is not found. + ForbiddenError + You do not have proper permissions to do the actions required. + + Returns + ------- + Dict[:class:`str`, Any] + Channel object. + """ + + message = await self._http.delete( + f"/channels/{self.id}", + headers={"X-Audit-Log-Reason": reason} + ) + + return message + class TextChannel(Channel): """A subclass of ``Channel`` representing text channels with all the same attributes.""" @@ -128,6 +164,7 @@ class TextChannel(Channel): around: Optional[Union[int, str, Snowflake]] = None, ) -> AsyncIterator[Dict[str, Any]]: """|coro| + Returns a list of messages in this channel. Examples @@ -193,6 +230,7 @@ class TextChannel(Channel): message_id: Optional[Snowflake, int, str], ) -> Dict[str, Any]: """|coro| + Returns a specific message in the channel. Parameters @@ -223,6 +261,7 @@ class TextChannel(Channel): self, messages: List[Snowflake], *, reason: Optional[str] = None ): """|coro| + Delete multiple messages in a single request. This method will not delete messages older than 2 weeks. @@ -239,7 +278,7 @@ class TextChannel(Channel): if any message provided is older than that or if any duplicate message IDs are provided. ForbiddenError You do not have proper permissions to do the actions required. - (You must have `MANAGE_MESSAGES` permission) + (You must have **MANAGE_MESSAGES** permission) """ await self._http.post( f"channels/{self.id}/messages/bulk-delete", @@ -251,6 +290,7 @@ class TextChannel(Channel): self, message_id: Optional[Snowflake, str, int], *, reason: Optional[str] = None ): """|coro| + Deletes only one specified message. Parameters @@ -268,7 +308,7 @@ class TextChannel(Channel): If message is not found. ForbiddenError You do not have proper permissions to do the actions required. - (You must have `MANAGE_MESSAGES` permission) + (You must have **MANAGE_MESSAGES** permission) """ await self._http.delete( f"channels/{self.id}/messages/{message_id}", @@ -285,6 +325,7 @@ class TextChannel(Channel): reason: Optional[str] = None, ): """|coro| + Purges a list of messages that meet the criteria specified in parameters. This method will not delete messages older than 2 weeks. @@ -307,7 +348,7 @@ class TextChannel(Channel): if any message provided is older than that or if any duplicate message IDs are provided. ForbiddenError You do not have proper permissions to do the actions required. - (You must have `MANAGE_MESSAGES` permission) + (You must have **MANAGE_MESSAGES** permission) """ iterator = self.history( diff --git a/melisa/models/user/user.py b/melisa/models/user/user.py index 2f91e7e..5d2ae40 100644 --- a/melisa/models/user/user.py +++ b/melisa/models/user/user.py @@ -166,14 +166,10 @@ class User(APIModelBase): @property def premium(self) -> Optional[PremiumTypes]: - """APINullable[:class:`~melisa.models.user.user.PremiumTypes`]: The - user their premium type in a usable enum. - """ return None if self.premium_type is None else PremiumTypes(self.premium_type) @property def flags(self) -> Optional[UserFlags]: - """Flags of user""" return None if self.flags is None else UserFlags(self.flags) def __str__(self):