update docs and channel delete

This commit is contained in:
grey-cat-1908 2022-03-27 17:03:46 +03:00
parent bda6b2244d
commit 076a8ccdf3
5 changed files with 85 additions and 16 deletions

View file

@ -3,16 +3,47 @@
Melisa Models Guild 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 Guild
---- ------
DefaultMessageNotificationLevel DefaultMessageNotificationLevel
~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: DefaultMessageNotificationLevel() .. autoclass:: DefaultMessageNotificationLevel()
ExplicitContentFilterLevel ExplicitContentFilterLevel
~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: ExplicitContentFilterLevel() .. autoclass:: ExplicitContentFilterLevel()
@ -22,7 +53,7 @@ MFALevel
.. autoclass:: MFALevel() .. autoclass:: MFALevel()
VerificationLevel VerificationLevel
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
.. autoclass:: VerificationLevel() .. autoclass:: VerificationLevel()
@ -37,7 +68,7 @@ PremiumTier
.. autoclass:: PremiumTier() .. autoclass:: PremiumTier()
SystemChannelFlags SystemChannelFlags
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
.. autoclass:: SystemChannelFlags() .. autoclass:: SystemChannelFlags()
@ -48,14 +79,13 @@ GuildFeatures
Guild Guild
~~~~~ ~~~~~
.. attributetable:: Guild .. attributetable:: Guild
.. autoclass:: Guild() .. autoclass:: Guild()
:inherited-members:
UnavailableGuild UnavailableGuild
~~~~~ ~~~~~~~~~~~~~~~~
.. attributetable:: UnavailableGuild .. attributetable:: UnavailableGuild
.. autoclass:: UnavailableGuild() .. autoclass:: UnavailableGuild()

View file

@ -27,4 +27,5 @@ User
.. attributetable:: User .. attributetable:: User
.. autoclass:: User() .. autoclass:: User()
:inherited-members:

View file

@ -2,3 +2,4 @@
# Full MIT License can be found in `LICENSE.txt` at the project root. # Full MIT License can be found in `LICENSE.txt` at the project root.
from .guild import * from .guild import *
from .channel import *

View file

@ -34,7 +34,7 @@ class ChannelType(IntEnum):
GUILD_STORE: GUILD_STORE:
A channel in which game developers can sell their game on Discord A channel in which game developers can sell their game on Discord
GUILD_NEWS_THREAD: GUILD_NEWS_THREAD:
A temporary sub-channel within a `GUILD_NEWS` channel A temporary sub-channel within a **GUILD_NEWS** channel
GUILD_PUBLIC_THREAD: GUILD_PUBLIC_THREAD:
A temporary sub-channel within a GUILD_TEXT channel A temporary sub-channel within a GUILD_TEXT channel
GUILD_PRIVATE_THREAD: GUILD_PRIVATE_THREAD:
@ -115,6 +115,42 @@ class Channel(APIModelBase):
def mention(self): def mention(self):
return f"<#{self.id}>" 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): class TextChannel(Channel):
"""A subclass of ``Channel`` representing text channels with all the same attributes.""" """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, around: Optional[Union[int, str, Snowflake]] = None,
) -> AsyncIterator[Dict[str, Any]]: ) -> AsyncIterator[Dict[str, Any]]:
"""|coro| """|coro|
Returns a list of messages in this channel. Returns a list of messages in this channel.
Examples Examples
@ -193,6 +230,7 @@ class TextChannel(Channel):
message_id: Optional[Snowflake, int, str], message_id: Optional[Snowflake, int, str],
) -> Dict[str, Any]: ) -> Dict[str, Any]:
"""|coro| """|coro|
Returns a specific message in the channel. Returns a specific message in the channel.
Parameters Parameters
@ -223,6 +261,7 @@ class TextChannel(Channel):
self, messages: List[Snowflake], *, reason: Optional[str] = None self, messages: List[Snowflake], *, reason: Optional[str] = None
): ):
"""|coro| """|coro|
Delete multiple messages in a single request. Delete multiple messages in a single request.
This method will not delete messages older than 2 weeks. 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. if any message provided is older than that or if any duplicate message IDs are provided.
ForbiddenError ForbiddenError
You do not have proper permissions to do the actions required. 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( await self._http.post(
f"channels/{self.id}/messages/bulk-delete", 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 self, message_id: Optional[Snowflake, str, int], *, reason: Optional[str] = None
): ):
"""|coro| """|coro|
Deletes only one specified message. Deletes only one specified message.
Parameters Parameters
@ -268,7 +308,7 @@ class TextChannel(Channel):
If message is not found. If message is not found.
ForbiddenError ForbiddenError
You do not have proper permissions to do the actions required. 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( await self._http.delete(
f"channels/{self.id}/messages/{message_id}", f"channels/{self.id}/messages/{message_id}",
@ -285,6 +325,7 @@ class TextChannel(Channel):
reason: Optional[str] = None, reason: Optional[str] = None,
): ):
"""|coro| """|coro|
Purges a list of messages that meet the criteria specified in parameters. Purges a list of messages that meet the criteria specified in parameters.
This method will not delete messages older than 2 weeks. 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. if any message provided is older than that or if any duplicate message IDs are provided.
ForbiddenError ForbiddenError
You do not have proper permissions to do the actions required. 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( iterator = self.history(

View file

@ -166,14 +166,10 @@ class User(APIModelBase):
@property @property
def premium(self) -> Optional[PremiumTypes]: 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) return None if self.premium_type is None else PremiumTypes(self.premium_type)
@property @property
def flags(self) -> Optional[UserFlags]: def flags(self) -> Optional[UserFlags]:
"""Flags of user"""
return None if self.flags is None else UserFlags(self.flags) return None if self.flags is None else UserFlags(self.flags)
def __str__(self): def __str__(self):