feat(client): add allowed_mentions and update docs

This commit is contained in:
grey-cat-1908 2022-04-29 16:01:11 +03:00
parent 11fe27a624
commit e770f4270e
6 changed files with 91 additions and 13 deletions

View file

@ -3,10 +3,81 @@
Melisa Models Message
===========================
Color
------
Color
~~~~~~
.. autoclass:: Color()
Embed
------
Embed
~~~~~~~
.. autoclass:: Embed()
EmbedType
~~~~~~~~~~
.. autoclass:: EmbedType()
EmbedThumbnail
~~~~~~~~~~~~~~~
.. autoclass:: EmbedThumbnail()
EmbedVideo
~~~~~~~~~~~~~~~
.. autoclass:: EmbedVideo()
EmbedImage
~~~~~~~~~~~~~~~
.. autoclass:: EmbedImage()
EmbedProvider
~~~~~~~~~~~~~~~
.. autoclass:: EmbedProvider()
EmbedAuthor
~~~~~~~~~~~~~~~
.. autoclass:: EmbedProvider()
EmbedFooter
~~~~~~~~~~~~~~~
.. autoclass:: EmbedFooter()
EmbedField
~~~~~~~~~~~~~~~
.. autoclass:: EmbedField()
File
-----
File
~~~~~~~~~~~~~~~~
.. autoclass:: File()
Message
--------
AllowedMentions
~~~~~~~~~~~~~~~~
.. autoclass:: AllowedMentions()
MessageType
~~~~~~~~~~~~~
@ -23,7 +94,7 @@ MessageFlags
.. autoclass:: MessageFlags()
Message
~~~~~~
~~~~~~~
.. attributetable:: Message
.. autoclass:: Message()

View file

@ -11,7 +11,7 @@ from typing import Dict, List, Union, Any, Iterable, Optional, Callable
from .rest import RESTApp
from .core.gateway import GatewayBotInfo
from .models.guild.channel import Channel
from .models import Activity
from .models import Activity, AllowedMentions
from .models.app.shard import Shard
from .models.app.intents import Intents
from .utils.snowflake import Snowflake
@ -43,6 +43,8 @@ class Client:
Can be generated using :class:`~models.user.presence.StatusType`
mobile: :class:`bool`
Set user device as mobile?
allowed_mentions: Optional[:class:`~melisa.models.message.message.AllowedMentions`]
Controls the mentions being processed in every message.
logs: :class:`Optional[None, str, Dict[str, Any]]`
The hint for configuring logging.
This can be `None` to disable logging automatically.
@ -69,6 +71,7 @@ class Client:
activity: Optional[Activity] = None,
status: str = None,
mobile: bool = False,
allowed_mentions: Optional[AllowedMentions] = None,
logs: Union[None, int, str, Dict[str, Any]] = "INFO",
):
self._loop = asyncio.get_event_loop()
@ -94,11 +97,13 @@ class Client:
else:
self.intents = intents
self._token = token
self._token: str = token
self._activity = activity
self._status = status
self._mobile = mobile
self._mobile: bool = mobile
self.allowed_mentions: AllowedMentions = allowed_mentions
self._none_guilds_cached = False
APIModelBase.set_client(self)

View file

@ -506,9 +506,7 @@ class MessageableChannel(Channel):
You do not have proper permissions to do the actions required.
(You must have ``MANAGE_MESSAGES`` permission)
"""
await self._client.rest.delete_message(
self.id, message_id, reason=reason
)
await self._client.rest.delete_message(self.id, message_id, reason=reason)
async def send(
self,
@ -520,7 +518,7 @@ class MessageableChannel(Channel):
file: File = None,
files: List[File] = None,
allowed_mentions: AllowedMentions = None,
delete_after: int = None
delete_after: int = None,
) -> Message:
"""|coro|
@ -581,6 +579,8 @@ class MessageableChannel(Channel):
# ToDo: add auto allowed_mentions from client
if allowed_mentions is not None:
payload["allowed_mentions"] = allowed_mentions.to_dict()
elif self._client.allowed_mentions is not None:
payload["allowed_mentions"] = self._client.allowed_mentions.to_dict()
content_type, data = create_form(payload, files)

View file

@ -109,7 +109,8 @@ class Webhook(APIModelBase):
reason: Optional[str] = None,
):
"""|coro|
Modify a webhook. Requires the ``MANAGE_WEBHOOKS permission``. Returns the updated webhook object on success.
Modify a webhook. Requires the ``MANAGE_WEBHOOKS permission``.
Returns the updated webhook object on success.
Parameters
----------

View file

@ -429,6 +429,7 @@ class Message(APIModelBase):
"""
if delay is not None:
async def delete(delete_after: float):
await asyncio.sleep(delete_after)
await self._client.rest.delete_message(self.channel_id, self.id)

View file

@ -72,7 +72,7 @@ class RESTApp:
channel_id: Union[Snowflake, str, int],
message_id: Union[Snowflake, str, int],
*,
reason: Optional[str] = None
reason: Optional[str] = None,
):
"""|coro|