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 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 Message
-------- --------
AllowedMentions
~~~~~~~~~~~~~~~~
.. autoclass:: AllowedMentions()
MessageType MessageType
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
@ -23,7 +94,7 @@ MessageFlags
.. autoclass:: MessageFlags() .. autoclass:: MessageFlags()
Message Message
~~~~~~ ~~~~~~~
.. attributetable:: Message .. attributetable:: Message
.. autoclass:: Message() .. autoclass:: Message()

View file

@ -11,7 +11,7 @@ from typing import Dict, List, Union, Any, Iterable, Optional, Callable
from .rest import RESTApp from .rest import RESTApp
from .core.gateway import GatewayBotInfo from .core.gateway import GatewayBotInfo
from .models.guild.channel import Channel from .models.guild.channel import Channel
from .models import Activity from .models import Activity, AllowedMentions
from .models.app.shard import Shard from .models.app.shard import Shard
from .models.app.intents import Intents from .models.app.intents import Intents
from .utils.snowflake import Snowflake from .utils.snowflake import Snowflake
@ -43,6 +43,8 @@ class Client:
Can be generated using :class:`~models.user.presence.StatusType` Can be generated using :class:`~models.user.presence.StatusType`
mobile: :class:`bool` mobile: :class:`bool`
Set user device as mobile? 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]]` logs: :class:`Optional[None, str, Dict[str, Any]]`
The hint for configuring logging. The hint for configuring logging.
This can be `None` to disable logging automatically. This can be `None` to disable logging automatically.
@ -69,6 +71,7 @@ class Client:
activity: Optional[Activity] = None, activity: Optional[Activity] = None,
status: str = None, status: str = None,
mobile: bool = False, mobile: bool = False,
allowed_mentions: Optional[AllowedMentions] = None,
logs: Union[None, int, str, Dict[str, Any]] = "INFO", logs: Union[None, int, str, Dict[str, Any]] = "INFO",
): ):
self._loop = asyncio.get_event_loop() self._loop = asyncio.get_event_loop()
@ -94,11 +97,13 @@ class Client:
else: else:
self.intents = intents self.intents = intents
self._token = token self._token: str = token
self._activity = activity self._activity = activity
self._status = status self._status = status
self._mobile = mobile self._mobile: bool = mobile
self.allowed_mentions: AllowedMentions = allowed_mentions
self._none_guilds_cached = False self._none_guilds_cached = False
APIModelBase.set_client(self) 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 do not have proper permissions to do the actions required.
(You must have ``MANAGE_MESSAGES`` permission) (You must have ``MANAGE_MESSAGES`` permission)
""" """
await self._client.rest.delete_message( await self._client.rest.delete_message(self.id, message_id, reason=reason)
self.id, message_id, reason=reason
)
async def send( async def send(
self, self,
@ -520,7 +518,7 @@ class MessageableChannel(Channel):
file: File = None, file: File = None,
files: List[File] = None, files: List[File] = None,
allowed_mentions: AllowedMentions = None, allowed_mentions: AllowedMentions = None,
delete_after: int = None delete_after: int = None,
) -> Message: ) -> Message:
"""|coro| """|coro|
@ -581,6 +579,8 @@ class MessageableChannel(Channel):
# ToDo: add auto allowed_mentions from client # ToDo: add auto allowed_mentions from client
if allowed_mentions is not None: if allowed_mentions is not None:
payload["allowed_mentions"] = allowed_mentions.to_dict() 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) content_type, data = create_form(payload, files)

View file

@ -109,7 +109,8 @@ class Webhook(APIModelBase):
reason: Optional[str] = None, reason: Optional[str] = None,
): ):
"""|coro| """|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 Parameters
---------- ----------

View file

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

View file

@ -69,10 +69,10 @@ class RESTApp:
async def delete_message( async def delete_message(
self, self,
channel_id: Union[Snowflake, str, int], channel_id: Union[Snowflake, str, int],
message_id: Union[Snowflake, str, int], message_id: Union[Snowflake, str, int],
*, *,
reason: Optional[str] = None reason: Optional[str] = None,
): ):
"""|coro| """|coro|