Add support for silent messages

This commit is contained in:
Rapptz 2023-02-08 15:40:33 -05:00
parent 93ed1646d2
commit 183675be74
5 changed files with 60 additions and 6 deletions

View File

@ -1315,6 +1315,7 @@ class Messageable:
mention_author: bool = ..., mention_author: bool = ...,
view: View = ..., view: View = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1334,6 +1335,7 @@ class Messageable:
mention_author: bool = ..., mention_author: bool = ...,
view: View = ..., view: View = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1353,6 +1355,7 @@ class Messageable:
mention_author: bool = ..., mention_author: bool = ...,
view: View = ..., view: View = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1372,6 +1375,7 @@ class Messageable:
mention_author: bool = ..., mention_author: bool = ...,
view: View = ..., view: View = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1392,6 +1396,7 @@ class Messageable:
mention_author: Optional[bool] = None, mention_author: Optional[bool] = None,
view: Optional[View] = None, view: Optional[View] = None,
suppress_embeds: bool = False, suppress_embeds: bool = False,
silent: bool = False,
) -> Message: ) -> Message:
"""|coro| """|coro|
@ -1472,6 +1477,11 @@ class Messageable:
Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.
.. versionadded:: 2.0 .. versionadded:: 2.0
silent: :class:`bool`
Whether to suppress push and desktop notifications for the message. This will increment the mention counter
in the UI, but will not actually send a notification.
.. versionadded:: 2.2
Raises Raises
-------- --------
@ -1514,10 +1524,12 @@ class Messageable:
if view and not hasattr(view, '__discord_ui_view__'): if view and not hasattr(view, '__discord_ui_view__'):
raise TypeError(f'view parameter must be View not {view.__class__.__name__}') raise TypeError(f'view parameter must be View not {view.__class__.__name__}')
if suppress_embeds: if suppress_embeds or silent:
from .message import MessageFlags # circular import from .message import MessageFlags # circular import
flags = MessageFlags._from_value(4) flags = MessageFlags._from_value(0)
flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
else: else:
flags = MISSING flags = MISSING

View File

@ -434,6 +434,22 @@ class MessageFlags(BaseFlags):
""" """
return 256 return 256
@flag_value
def suppress_notifications(self):
""":class:`bool`: Returns ``True`` if the message will not trigger push and desktop notifications.
.. versionadded:: 2.2
"""
return 4096
@alias_flag_value
def silent(self):
""":class:`bool`: Alias for :attr:`suppress_notifications`.
.. versionadded:: 2.2
"""
return 4096
@fill_with_flags() @fill_with_flags()
class PublicUserFlags(BaseFlags): class PublicUserFlags(BaseFlags):

View File

@ -690,6 +690,7 @@ class InteractionResponse(Generic[ClientT]):
ephemeral: bool = False, ephemeral: bool = False,
allowed_mentions: AllowedMentions = MISSING, allowed_mentions: AllowedMentions = MISSING,
suppress_embeds: bool = False, suppress_embeds: bool = False,
silent: bool = False,
delete_after: Optional[float] = None, delete_after: Optional[float] = None,
) -> None: ) -> None:
"""|coro| """|coro|
@ -723,6 +724,11 @@ class InteractionResponse(Generic[ClientT]):
more information. more information.
suppress_embeds: :class:`bool` suppress_embeds: :class:`bool`
Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.
silent: :class:`bool`
Whether to suppress push and desktop notifications for the message. This will increment the mention counter
in the UI, but will not actually send a notification.
.. versionadded:: 2.2
delete_after: :class:`float` delete_after: :class:`float`
If provided, the number of seconds to wait in the background If provided, the number of seconds to wait in the background
before deleting the message we just sent. If the deletion fails, before deleting the message we just sent. If the deletion fails,
@ -744,10 +750,11 @@ class InteractionResponse(Generic[ClientT]):
if self._response_type: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
if ephemeral or suppress_embeds: if ephemeral or suppress_embeds or silent:
flags = MessageFlags._from_value(0) flags = MessageFlags._from_value(0)
flags.ephemeral = ephemeral flags.ephemeral = ephemeral
flags.suppress_embeds = suppress_embeds flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
else: else:
flags = MISSING flags = MISSING

View File

@ -1535,6 +1535,7 @@ class Webhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: Literal[True], wait: Literal[True],
suppress_embeds: bool = MISSING, suppress_embeds: bool = MISSING,
silent: bool = MISSING,
) -> WebhookMessage: ) -> WebhookMessage:
... ...
@ -1557,6 +1558,7 @@ class Webhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: Literal[False] = ..., wait: Literal[False] = ...,
suppress_embeds: bool = MISSING, suppress_embeds: bool = MISSING,
silent: bool = MISSING,
) -> None: ) -> None:
... ...
@ -1578,6 +1580,7 @@ class Webhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: bool = False, wait: bool = False,
suppress_embeds: bool = False, suppress_embeds: bool = False,
silent: bool = False,
) -> Optional[WebhookMessage]: ) -> Optional[WebhookMessage]:
"""|coro| """|coro|
@ -1658,6 +1661,11 @@ class Webhook(BaseWebhook):
Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.
.. versionadded:: 2.0 .. versionadded:: 2.0
silent: :class:`bool`
Whether to suppress push and desktop notifications for the message. This will increment the mention counter
in the UI, but will not actually send a notification.
.. versionadded:: 2.2
Raises Raises
-------- --------
@ -1688,10 +1696,11 @@ class Webhook(BaseWebhook):
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None) previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
if content is None: if content is None:
content = MISSING content = MISSING
if ephemeral or suppress_embeds: if ephemeral or suppress_embeds or silent:
flags = MessageFlags._from_value(0) flags = MessageFlags._from_value(0)
flags.ephemeral = ephemeral flags.ephemeral = ephemeral
flags.suppress_embeds = suppress_embeds flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
else: else:
flags = MISSING flags = MISSING

View File

@ -870,6 +870,7 @@ class SyncWebhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: Literal[True], wait: Literal[True],
suppress_embeds: bool = MISSING, suppress_embeds: bool = MISSING,
silent: bool = MISSING,
) -> SyncWebhookMessage: ) -> SyncWebhookMessage:
... ...
@ -890,6 +891,7 @@ class SyncWebhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: Literal[False] = ..., wait: Literal[False] = ...,
suppress_embeds: bool = MISSING, suppress_embeds: bool = MISSING,
silent: bool = MISSING,
) -> None: ) -> None:
... ...
@ -909,6 +911,7 @@ class SyncWebhook(BaseWebhook):
thread_name: str = MISSING, thread_name: str = MISSING,
wait: bool = False, wait: bool = False,
suppress_embeds: bool = False, suppress_embeds: bool = False,
silent: bool = False,
) -> Optional[SyncWebhookMessage]: ) -> Optional[SyncWebhookMessage]:
"""Sends a message using the webhook. """Sends a message using the webhook.
@ -968,6 +971,11 @@ class SyncWebhook(BaseWebhook):
Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.
.. versionadded:: 2.0 .. versionadded:: 2.0
silent: :class:`bool`
Whether to suppress push and desktop notifications for the message. This will increment the mention counter
in the UI, but will not actually send a notification.
.. versionadded:: 2.2
Raises Raises
-------- --------
@ -997,8 +1005,10 @@ class SyncWebhook(BaseWebhook):
if content is None: if content is None:
content = MISSING content = MISSING
if suppress_embeds: if suppress_embeds or silent:
flags = MessageFlags._from_value(4) flags = MessageFlags._from_value(0)
flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
else: else:
flags = MISSING flags = MISSING