Browse Source

Add support for silent messages

pull/10109/head
Rapptz 2 years ago
committed by dolfies
parent
commit
6ec3ecd493
  1. 16
      discord/abc.py
  2. 16
      discord/flags.py
  3. 11
      discord/webhook/async_.py
  4. 14
      discord/webhook/sync.py

16
discord/abc.py

@ -1435,6 +1435,7 @@ class Messageable:
reference: Union[Message, MessageReference, PartialMessage] = ..., reference: Union[Message, MessageReference, PartialMessage] = ...,
mention_author: bool = ..., mention_author: bool = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1452,6 +1453,7 @@ class Messageable:
reference: Union[Message, MessageReference, PartialMessage] = ..., reference: Union[Message, MessageReference, PartialMessage] = ...,
mention_author: bool = ..., mention_author: bool = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1469,6 +1471,7 @@ class Messageable:
reference: Union[Message, MessageReference, PartialMessage] = ..., reference: Union[Message, MessageReference, PartialMessage] = ...,
mention_author: bool = ..., mention_author: bool = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1486,6 +1489,7 @@ class Messageable:
reference: Union[Message, MessageReference, PartialMessage] = ..., reference: Union[Message, MessageReference, PartialMessage] = ...,
mention_author: bool = ..., mention_author: bool = ...,
suppress_embeds: bool = ..., suppress_embeds: bool = ...,
silent: bool = ...,
) -> Message: ) -> Message:
... ...
@ -1503,6 +1507,7 @@ class Messageable:
reference: Optional[Union[Message, MessageReference, PartialMessage]] = None, reference: Optional[Union[Message, MessageReference, PartialMessage]] = None,
mention_author: Optional[bool] = None, mention_author: Optional[bool] = None,
suppress_embeds: bool = False, suppress_embeds: bool = False,
silent: bool = False,
) -> Message: ) -> Message:
"""|coro| """|coro|
@ -1566,6 +1571,11 @@ class Messageable:
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``.
.. 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.0 .. versionadded:: 2.0
Raises Raises
@ -1608,10 +1618,12 @@ class Messageable:
else: else:
reference_dict = MISSING reference_dict = MISSING
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

16
discord/flags.py

@ -577,6 +577,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.0
"""
return 4096
@alias_flag_value
def silent(self):
""":class:`bool`: Alias for :attr:`suppress_notifications`.
.. versionadded:: 2.0
"""
return 4096
@fill_with_flags() @fill_with_flags()
class PublicUserFlags(BaseFlags): class PublicUserFlags(BaseFlags):

11
discord/webhook/async_.py

@ -1321,6 +1321,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:
... ...
@ -1341,6 +1342,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:
... ...
@ -1360,6 +1362,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|
@ -1425,6 +1428,11 @@ class Webhook(BaseWebhook):
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``.
.. 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.0 .. versionadded:: 2.0
Raises Raises
@ -1454,9 +1462,10 @@ 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 suppress_embeds: if suppress_embeds or silent:
flags = MessageFlags._from_value(0) flags = MessageFlags._from_value(0)
flags.suppress_embeds = suppress_embeds flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
else: else:
flags = MISSING flags = MISSING

14
discord/webhook/sync.py

@ -869,6 +869,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:
... ...
@ -889,6 +890,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:
... ...
@ -908,6 +910,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.
@ -966,6 +969,11 @@ class SyncWebhook(BaseWebhook):
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``.
.. 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.0 .. versionadded:: 2.0
Raises Raises
@ -996,8 +1004,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

Loading…
Cancel
Save