Skip to content

Commit 752a38c

Browse files
authored
feat: Message.enforce_nonce (#2370)
Signed-off-by: Dorukyum <[email protected]>
1 parent 76a3e4c commit 752a38c

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ These changes are available on the `master` branch, but have not yet been releas
9595
([#2350](https://github.com/Pycord-Development/pycord/pull/2350))
9696
- Added support for voice channel statuses.
9797
([#2368](https://github.com/Pycord-Development/pycord/pull/2368))
98+
- Added `Message.enforce_nonce`.
99+
([#2370](https://github.com/Pycord-Development/pycord/pull/2370))
98100

99101
### Changed
100102

discord/abc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ async def send(
13461346
stickers: Sequence[GuildSticker | StickerItem] = ...,
13471347
delete_after: float = ...,
13481348
nonce: str | int = ...,
1349+
enforce_nonce: bool = ...,
13491350
allowed_mentions: AllowedMentions = ...,
13501351
reference: Message | MessageReference | PartialMessage = ...,
13511352
mention_author: bool = ...,
@@ -1365,6 +1366,7 @@ async def send(
13651366
stickers: Sequence[GuildSticker | StickerItem] = ...,
13661367
delete_after: float = ...,
13671368
nonce: str | int = ...,
1369+
enforce_nonce: bool = ...,
13681370
allowed_mentions: AllowedMentions = ...,
13691371
reference: Message | MessageReference | PartialMessage = ...,
13701372
mention_author: bool = ...,
@@ -1384,6 +1386,7 @@ async def send(
13841386
stickers: Sequence[GuildSticker | StickerItem] = ...,
13851387
delete_after: float = ...,
13861388
nonce: str | int = ...,
1389+
enforce_nonce: bool = ...,
13871390
allowed_mentions: AllowedMentions = ...,
13881391
reference: Message | MessageReference | PartialMessage = ...,
13891392
mention_author: bool = ...,
@@ -1403,6 +1406,7 @@ async def send(
14031406
stickers: Sequence[GuildSticker | StickerItem] = ...,
14041407
delete_after: float = ...,
14051408
nonce: str | int = ...,
1409+
enforce_nonce: bool = ...,
14061410
allowed_mentions: AllowedMentions = ...,
14071411
reference: Message | MessageReference | PartialMessage = ...,
14081412
mention_author: bool = ...,
@@ -1423,6 +1427,7 @@ async def send(
14231427
stickers=None,
14241428
delete_after=None,
14251429
nonce=None,
1430+
enforce_nonce=None,
14261431
allowed_mentions=None,
14271432
reference=None,
14281433
mention_author=None,
@@ -1463,6 +1468,10 @@ async def send(
14631468
nonce: :class:`int`
14641469
The nonce to use for sending this message. If the message was successfully sent,
14651470
then the message will have a nonce with this value.
1471+
enforce_nonce: Optional[:class:`bool`]
1472+
Whether :attr:`nonce` is enforced to be validated.
1473+
1474+
.. versionadded:: 2.5
14661475
delete_after: :class:`float`
14671476
If provided, the number of seconds to wait in the background
14681477
before deleting the message we just sent. If the deletion fails,
@@ -1602,6 +1611,7 @@ async def send(
16021611
embed=embed,
16031612
embeds=embeds,
16041613
nonce=nonce,
1614+
enforce_nonce=nonce,
16051615
message_reference=reference,
16061616
stickers=stickers,
16071617
components=components,
@@ -1627,6 +1637,7 @@ async def send(
16271637
embed=embed,
16281638
embeds=embeds,
16291639
nonce=nonce,
1640+
enforce_nonce=nonce,
16301641
allowed_mentions=allowed_mentions,
16311642
message_reference=reference,
16321643
stickers=stickers,
@@ -1644,6 +1655,7 @@ async def send(
16441655
embed=embed,
16451656
embeds=embeds,
16461657
nonce=nonce,
1658+
enforce_nonce=nonce,
16471659
allowed_mentions=allowed_mentions,
16481660
message_reference=reference,
16491661
stickers=stickers,

discord/http.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ def send_message(
465465
embed: embed.Embed | None = None,
466466
embeds: list[embed.Embed] | None = None,
467467
nonce: str | None = None,
468+
enforce_nonce: bool | None = None,
468469
allowed_mentions: message.AllowedMentions | None = None,
469470
message_reference: message.MessageReference | None = None,
470471
stickers: list[sticker.StickerItem] | None = None,
@@ -489,6 +490,9 @@ def send_message(
489490
if nonce:
490491
payload["nonce"] = nonce
491492

493+
if enforce_nonce:
494+
payload["enforce_nonce"] = enforce_nonce
495+
492496
if allowed_mentions:
493497
payload["allowed_mentions"] = allowed_mentions
494498

@@ -521,6 +525,7 @@ def send_multipart_helper(
521525
embed: embed.Embed | None = None,
522526
embeds: Iterable[embed.Embed | None] | None = None,
523527
nonce: str | None = None,
528+
enforce_nonce: bool | None = None,
524529
allowed_mentions: message.AllowedMentions | None = None,
525530
message_reference: message.MessageReference | None = None,
526531
stickers: list[sticker.StickerItem] | None = None,
@@ -538,6 +543,8 @@ def send_multipart_helper(
538543
payload["embeds"] = embeds
539544
if nonce:
540545
payload["nonce"] = nonce
546+
if enforce_nonce:
547+
payload["enforce_nonce"] = enforce_nonce
541548
if allowed_mentions:
542549
payload["allowed_mentions"] = allowed_mentions
543550
if message_reference:
@@ -581,6 +588,7 @@ def send_files(
581588
embed: embed.Embed | None = None,
582589
embeds: list[embed.Embed] | None = None,
583590
nonce: str | None = None,
591+
enforce_nonce: bool | None = None,
584592
allowed_mentions: message.AllowedMentions | None = None,
585593
message_reference: message.MessageReference | None = None,
586594
stickers: list[sticker.StickerItem] | None = None,
@@ -596,6 +604,7 @@ def send_files(
596604
embed=embed,
597605
embeds=embeds,
598606
nonce=nonce,
607+
enforce_nonce=enforce_nonce,
599608
allowed_mentions=allowed_mentions,
600609
message_reference=message_reference,
601610
stickers=stickers,

discord/message.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ class Message(Hashable):
640640
nonce: Optional[Union[:class:`str`, :class:`int`]]
641641
The value used by the discord guild and the client to verify that the message is successfully sent.
642642
This is not stored long term within Discord's servers and is only used ephemerally.
643+
enforce_nonce: Optional[:class:`bool`]
644+
Whether :attr:`nonce` is enforced to be validated.
645+
646+
.. versionadded:: 2.5
643647
embeds: List[:class:`Embed`]
644648
A list of embeds the message has.
645649
channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`, :class:`GroupChannel`, :class:`PartialMessageable`]
@@ -748,6 +752,7 @@ class Message(Hashable):
748752
"author",
749753
"attachments",
750754
"nonce",
755+
"enforce_nonce",
751756
"pinned",
752757
"role_mentions",
753758
"type",
@@ -802,6 +807,7 @@ def __init__(
802807
self.tts: bool = data["tts"]
803808
self.content: str = data["content"]
804809
self.nonce: int | str | None = data.get("nonce")
810+
self.enforce_nonce: bool | None = data.get("enforce_nonce")
805811
self.stickers: list[StickerItem] = [
806812
StickerItem(data=d, state=state) for d in data.get("sticker_items", [])
807813
]
@@ -983,6 +989,9 @@ def _handle_embeds(self, value: list[EmbedPayload]) -> None:
983989
def _handle_nonce(self, value: str | int) -> None:
984990
self.nonce = value
985991

992+
def _handle_enforce_none(self, value: bool) -> None:
993+
self.enforce_nonce = value
994+
986995
def _handle_author(self, author: UserPayload) -> None:
987996
self.author = self._state.store_user(author)
988997
if isinstance(self.guild, Guild):

discord/types/message.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Message(TypedDict):
111111
mention_channels: NotRequired[list[ChannelMention]]
112112
reactions: NotRequired[list[Reaction]]
113113
nonce: NotRequired[int | str]
114+
enforce_nonce: NotRequired[bool]
114115
webhook_id: NotRequired[Snowflake]
115116
activity: NotRequired[MessageActivity]
116117
application: NotRequired[MessageApplication]

0 commit comments

Comments
 (0)