Skip to content

Commit

Permalink
feat: Message.enforce_nonce (#2370)
Browse files Browse the repository at this point in the history
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
  • Loading branch information
Dorukyum committed Feb 28, 2024
1 parent 76a3e4c commit 752a38c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -95,6 +95,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2350](https://github.com/Pycord-Development/pycord/pull/2350))
- Added support for voice channel statuses.
([#2368](https://github.com/Pycord-Development/pycord/pull/2368))
- Added `Message.enforce_nonce`.
([#2370](https://github.com/Pycord-Development/pycord/pull/2370))

### Changed

Expand Down
12 changes: 12 additions & 0 deletions discord/abc.py
Expand Up @@ -1346,6 +1346,7 @@ async def send(
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
Expand All @@ -1365,6 +1366,7 @@ async def send(
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
Expand All @@ -1384,6 +1386,7 @@ async def send(
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
Expand All @@ -1403,6 +1406,7 @@ async def send(
stickers: Sequence[GuildSticker | StickerItem] = ...,
delete_after: float = ...,
nonce: str | int = ...,
enforce_nonce: bool = ...,
allowed_mentions: AllowedMentions = ...,
reference: Message | MessageReference | PartialMessage = ...,
mention_author: bool = ...,
Expand All @@ -1423,6 +1427,7 @@ async def send(
stickers=None,
delete_after=None,
nonce=None,
enforce_nonce=None,
allowed_mentions=None,
reference=None,
mention_author=None,
Expand Down Expand Up @@ -1463,6 +1468,10 @@ async def send(
nonce: :class:`int`
The nonce to use for sending this message. If the message was successfully sent,
then the message will have a nonce with this value.
enforce_nonce: Optional[:class:`bool`]
Whether :attr:`nonce` is enforced to be validated.
.. versionadded:: 2.5
delete_after: :class:`float`
If provided, the number of seconds to wait in the background
before deleting the message we just sent. If the deletion fails,
Expand Down Expand Up @@ -1602,6 +1611,7 @@ async def send(
embed=embed,
embeds=embeds,
nonce=nonce,
enforce_nonce=nonce,
message_reference=reference,
stickers=stickers,
components=components,
Expand All @@ -1627,6 +1637,7 @@ async def send(
embed=embed,
embeds=embeds,
nonce=nonce,
enforce_nonce=nonce,
allowed_mentions=allowed_mentions,
message_reference=reference,
stickers=stickers,
Expand All @@ -1644,6 +1655,7 @@ async def send(
embed=embed,
embeds=embeds,
nonce=nonce,
enforce_nonce=nonce,
allowed_mentions=allowed_mentions,
message_reference=reference,
stickers=stickers,
Expand Down
9 changes: 9 additions & 0 deletions discord/http.py
Expand Up @@ -465,6 +465,7 @@ def send_message(
embed: embed.Embed | None = None,
embeds: list[embed.Embed] | None = None,
nonce: str | None = None,
enforce_nonce: bool | None = None,
allowed_mentions: message.AllowedMentions | None = None,
message_reference: message.MessageReference | None = None,
stickers: list[sticker.StickerItem] | None = None,
Expand All @@ -489,6 +490,9 @@ def send_message(
if nonce:
payload["nonce"] = nonce

if enforce_nonce:
payload["enforce_nonce"] = enforce_nonce

if allowed_mentions:
payload["allowed_mentions"] = allowed_mentions

Expand Down Expand Up @@ -521,6 +525,7 @@ def send_multipart_helper(
embed: embed.Embed | None = None,
embeds: Iterable[embed.Embed | None] | None = None,
nonce: str | None = None,
enforce_nonce: bool | None = None,
allowed_mentions: message.AllowedMentions | None = None,
message_reference: message.MessageReference | None = None,
stickers: list[sticker.StickerItem] | None = None,
Expand All @@ -538,6 +543,8 @@ def send_multipart_helper(
payload["embeds"] = embeds
if nonce:
payload["nonce"] = nonce
if enforce_nonce:
payload["enforce_nonce"] = enforce_nonce
if allowed_mentions:
payload["allowed_mentions"] = allowed_mentions
if message_reference:
Expand Down Expand Up @@ -581,6 +588,7 @@ def send_files(
embed: embed.Embed | None = None,
embeds: list[embed.Embed] | None = None,
nonce: str | None = None,
enforce_nonce: bool | None = None,
allowed_mentions: message.AllowedMentions | None = None,
message_reference: message.MessageReference | None = None,
stickers: list[sticker.StickerItem] | None = None,
Expand All @@ -596,6 +604,7 @@ def send_files(
embed=embed,
embeds=embeds,
nonce=nonce,
enforce_nonce=enforce_nonce,
allowed_mentions=allowed_mentions,
message_reference=message_reference,
stickers=stickers,
Expand Down
9 changes: 9 additions & 0 deletions discord/message.py
Expand Up @@ -640,6 +640,10 @@ class Message(Hashable):
nonce: Optional[Union[:class:`str`, :class:`int`]]
The value used by the discord guild and the client to verify that the message is successfully sent.
This is not stored long term within Discord's servers and is only used ephemerally.
enforce_nonce: Optional[:class:`bool`]
Whether :attr:`nonce` is enforced to be validated.
.. versionadded:: 2.5
embeds: List[:class:`Embed`]
A list of embeds the message has.
channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`, :class:`GroupChannel`, :class:`PartialMessageable`]
Expand Down Expand Up @@ -748,6 +752,7 @@ class Message(Hashable):
"author",
"attachments",
"nonce",
"enforce_nonce",
"pinned",
"role_mentions",
"type",
Expand Down Expand Up @@ -802,6 +807,7 @@ def __init__(
self.tts: bool = data["tts"]
self.content: str = data["content"]
self.nonce: int | str | None = data.get("nonce")
self.enforce_nonce: bool | None = data.get("enforce_nonce")
self.stickers: list[StickerItem] = [
StickerItem(data=d, state=state) for d in data.get("sticker_items", [])
]
Expand Down Expand Up @@ -983,6 +989,9 @@ def _handle_embeds(self, value: list[EmbedPayload]) -> None:
def _handle_nonce(self, value: str | int) -> None:
self.nonce = value

def _handle_enforce_none(self, value: bool) -> None:
self.enforce_nonce = value

def _handle_author(self, author: UserPayload) -> None:
self.author = self._state.store_user(author)
if isinstance(self.guild, Guild):
Expand Down
1 change: 1 addition & 0 deletions discord/types/message.py
Expand Up @@ -111,6 +111,7 @@ class Message(TypedDict):
mention_channels: NotRequired[list[ChannelMention]]
reactions: NotRequired[list[Reaction]]
nonce: NotRequired[int | str]
enforce_nonce: NotRequired[bool]
webhook_id: NotRequired[Snowflake]
activity: NotRequired[MessageActivity]
application: NotRequired[MessageApplication]
Expand Down

0 comments on commit 752a38c

Please sign in to comment.