Browse Source

Fix methods that modifies messages to allow modifying only the components (#170)

pull/1923/head
d4n3436 GitHub 3 years ago
parent
commit
0dc74f999d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions
  1. +6
    -4
      src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
  2. +4
    -3
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  3. +1
    -1
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs

+ 6
- 4
src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs View File

@@ -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<API.Embed>() : 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<API.Embed>() : null;


+ 4
- 3
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -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)


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs View File

@@ -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));


Loading…
Cancel
Save