From 0dc74f999de9e535d5acaebbb054491d5b5e3d34 Mon Sep 17 00:00:00 2001 From: d4n3436 Date: Tue, 21 Sep 2021 14:18:18 -0500 Subject: [PATCH] Fix methods that modifies messages to allow modifying only the components (#170) --- .../Entities/Interactions/InteractionHelper.cs | 10 ++++++---- .../Entities/Messages/MessageHelper.cs | 7 ++++--- .../Message Components/SocketMessageComponent.cs | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index e79cb6e2f..ce7953e1e 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -340,9 +340,10 @@ namespace Discord.Rest var embeds = args.Embeds; bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(message.Content); - bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0) || message.Embeds.Any(); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || message.Embeds.Any(); + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; - if (!hasText && !hasEmbeds) + if (!hasComponents && !hasText && !hasEmbeds) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; @@ -383,9 +384,10 @@ namespace Discord.Rest var embeds = args.Embeds; bool hasText = !string.IsNullOrEmpty(args.Content.GetValueOrDefault()); - bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0; + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; - if (!hasText && !hasEmbeds) + if (!hasComponents && !hasText && !hasEmbeds) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 0faca002d..d50f453d7 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -38,7 +38,7 @@ namespace Discord.Rest var embeds = args.Embeds; bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content); - bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0) || msg.Embeds.Any(); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || msg.Embeds.Any(); if (!hasText && !hasEmbeds) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); @@ -101,9 +101,10 @@ namespace Discord.Rest var embeds = args.Embeds; bool hasText = args.Content.IsSpecified && string.IsNullOrEmpty(args.Content.Value); - bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0; + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; - if (!hasText && !hasEmbeds) + if (!hasComponents && !hasText && !hasEmbeds) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); if (args.AllowedMentions.IsSpecified) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs index 5daffc2cd..2b834d78b 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs @@ -150,7 +150,7 @@ namespace Discord.WebSocket var embeds = args.Embeds; bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(Message.Content); - bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0) || Message.Embeds.Any(); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || Message.Embeds.Any(); if (!hasText && !hasEmbeds) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content));