diff --git a/src/Disqord.Core/Entities/Local/Message/Extensions/LocalMessageExtensions.cs b/src/Disqord.Core/Entities/Local/Message/Extensions/LocalMessageExtensions.cs index 145a85cd5..39d66dd9c 100644 --- a/src/Disqord.Core/Entities/Local/Message/Extensions/LocalMessageExtensions.cs +++ b/src/Disqord.Core/Entities/Local/Message/Extensions/LocalMessageExtensions.cs @@ -61,15 +61,37 @@ public static TMessage WithReply(this TMessage message, Snowflake mess /// /// The instance. /// The nonce. + /// Whether the nonce should be enforced. /// The type. /// /// The input instance. /// /// - public static TMessage WithNonce(this TMessage message, string nonce) + public static TMessage WithNonce(this TMessage message, string nonce, bool? enforceNonce = null) where TMessage : LocalMessage { message.Nonce = nonce; + message.ShouldEnforceNonce = Optional.FromNullable(enforceNonce); + return message; + } + + /// + /// Sets whether the nonce the uniqueness check of a nonce should be enforced on this message. + /// + /// + /// + /// + /// The instance. + /// Whether the nonce should be enforced. + /// The type. + /// + /// The input instance. + /// + /// + public static TMessage EnforceNonce(this TMessage message, bool enforceNonce) + where TMessage : LocalMessage + { + message.ShouldEnforceNonce = enforceNonce; return message; } } diff --git a/src/Disqord.Core/Entities/Local/Message/LocalMessage.cs b/src/Disqord.Core/Entities/Local/Message/LocalMessage.cs index 74f26652a..e5074e7f6 100644 --- a/src/Disqord.Core/Entities/Local/Message/LocalMessage.cs +++ b/src/Disqord.Core/Entities/Local/Message/LocalMessage.cs @@ -25,6 +25,15 @@ public class LocalMessage : LocalMessageBase, ILocalConstruct /// public Optional Nonce { get; set; } + /// + /// Gets or sets whether the uniqueness check of a nonce should be enforced. + /// + /// + /// If set to true and another message with the same nonce was created by the bot in the past few minutes, + /// that message will be returned. + /// + public Optional ShouldEnforceNonce { get; set; } + /// /// Instantiates a new . /// @@ -40,6 +49,7 @@ protected LocalMessage(LocalMessage other) { Reference = other.Reference.Clone(); Nonce = other.Nonce; + ShouldEnforceNonce = other.ShouldEnforceNonce; } /// diff --git a/src/Disqord.Rest.Api/Content/Json/CreateMessageJsonRestRequestContent.cs b/src/Disqord.Rest.Api/Content/Json/CreateMessageJsonRestRequestContent.cs index d5a82d8e6..c80551574 100644 --- a/src/Disqord.Rest.Api/Content/Json/CreateMessageJsonRestRequestContent.cs +++ b/src/Disqord.Rest.Api/Content/Json/CreateMessageJsonRestRequestContent.cs @@ -37,6 +37,9 @@ public class CreateMessageJsonRestRequestContent : JsonModelRestRequestContent, [JsonProperty("flags")] public Optional Flags; + [JsonProperty("enforce_nonce")] + public Optional EnforceNonce; + IList IAttachmentRestRequestContent.Attachments { set => Attachments = new(value); diff --git a/src/Disqord.Rest/Extensions/RestClientExtensions.Channel.cs b/src/Disqord.Rest/Extensions/RestClientExtensions.Channel.cs index 92b136a48..a7966fe0c 100644 --- a/src/Disqord.Rest/Extensions/RestClientExtensions.Channel.cs +++ b/src/Disqord.Rest/Extensions/RestClientExtensions.Channel.cs @@ -261,7 +261,8 @@ public static async Task SendMessageAsync(this IRestClient client, MessageReference = Optional.Convert(message.Reference, reference => reference.ToModel()), Components = Optional.Convert(message.Components, components => components.Select(component => component.ToModel()).ToArray()), StickerIds = Optional.Convert(message.StickerIds, stickerIds => stickerIds.ToArray()), - Flags = message.Flags + Flags = message.Flags, + EnforceNonce = message.ShouldEnforceNonce }; Task task; @@ -649,7 +650,8 @@ public static async Task CreateForumThreadAsync(this IRestClient MessageReference = Optional.Convert(message.Reference, reference => reference.ToModel()), Components = Optional.Convert(message.Components, components => components.Select(component => component.ToModel()).ToArray()), StickerIds = Optional.Convert(message.StickerIds, stickerIds => stickerIds.ToArray()), - Flags = message.Flags + Flags = message.Flags, + EnforceNonce = message.ShouldEnforceNonce }; var forumContent = new CreateForumThreadJsonRestRequestContent