@@ -7602,7 +7602,7 @@ | |||||
Gets or sets a single embed for this message. | Gets or sets a single embed for this message. | ||||
</summary> | </summary> | ||||
<remarks> | <remarks> | ||||
This property will be added to the <see cref="P:Discord.MessageProperties.Embed"/> array, in the future please use the array rather then this property. | |||||
This property will be added to the <see cref="P:Discord.MessageProperties.Embeds"/> array, in the future please use the array rather than this property. | |||||
</remarks> | </remarks> | ||||
</member> | </member> | ||||
<member name="P:Discord.MessageProperties.Embeds"> | <member name="P:Discord.MessageProperties.Embeds"> | ||||
@@ -22,7 +22,7 @@ namespace Discord | |||||
/// Gets or sets a single embed for this message. | /// Gets or sets a single embed for this message. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// This property will be added to the <see cref="Embed"/> array, in the future please use the array rather then this property. | |||||
/// This property will be added to the <see cref="Embeds"/> array, in the future please use the array rather than this property. | |||||
/// </remarks> | /// </remarks> | ||||
public Optional<Embed> Embed { get; set; } | public Optional<Embed> Embed { get; set; } | ||||
@@ -296,15 +296,33 @@ namespace Discord.Rest | |||||
var args = new MessageProperties(); | var args = new MessageProperties(); | ||||
func(args); | func(args); | ||||
var embed = args.Embed; | |||||
var embeds = args.Embeds; | |||||
bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(message.Content); | bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(message.Content); | ||||
bool hasEmbed = args.Embeds.IsSpecified ? args.Embeds.Value != null : message.Embeds.Any(); | |||||
if (!hasText && !hasEmbed) | |||||
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)); | Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); | ||||
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null; | |||||
if (embed.IsSpecified && embed.Value != null) | |||||
{ | |||||
apiEmbeds.Add(embed.Value.ToModel()); | |||||
} | |||||
if (embeds.IsSpecified && embeds.Value != null) | |||||
{ | |||||
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); | |||||
} | |||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
var apiArgs = new API.Rest.ModifyInteractionResponseParams | var apiArgs = new API.Rest.ModifyInteractionResponseParams | ||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
Embeds = args.Embeds.IsSpecified ? args.Embeds.Value.Select(x => x.ToModel()).ToArray() : Optional.Create<API.Embed[]>(), | |||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | ||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | ||||
}; | }; | ||||
@@ -321,10 +339,33 @@ namespace Discord.Rest | |||||
var args = new MessageProperties(); | var args = new MessageProperties(); | ||||
func(args); | func(args); | ||||
var embed = args.Embed; | |||||
var embeds = args.Embeds; | |||||
bool hasText = !string.IsNullOrEmpty(args.Content.GetValueOrDefault()); | |||||
bool hasEmbeds = (embed.IsSpecified && embed.Value != null) || (embeds.IsSpecified && embeds.Value?.Length > 0); | |||||
if (!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; | |||||
if (embed.IsSpecified && embed.Value != null) | |||||
{ | |||||
apiEmbeds.Add(embed.Value.ToModel()); | |||||
} | |||||
if (embeds.IsSpecified && embeds.Value != null) | |||||
{ | |||||
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); | |||||
} | |||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
var apiArgs = new ModifyInteractionResponseParams | var apiArgs = new ModifyInteractionResponseParams | ||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
Embeds = args.Embeds.IsSpecified ? args.Embeds.Value?.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, | |||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified, | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified, | ||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | ||||
Flags = args.Flags | Flags = args.Flags | ||||
@@ -1,3 +1,4 @@ | |||||
using Discord.API; | |||||
using Discord.API.Rest; | using Discord.API.Rest; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
@@ -33,9 +34,13 @@ namespace Discord.Rest | |||||
if (msg.Author.Id != client.CurrentUser.Id && (args.Content.IsSpecified || args.Embeds.IsSpecified || args.AllowedMentions.IsSpecified)) | if (msg.Author.Id != client.CurrentUser.Id && (args.Content.IsSpecified || args.Embeds.IsSpecified || args.AllowedMentions.IsSpecified)) | ||||
throw new InvalidOperationException("Only the author of a message may modify the message content, embed, or allowed mentions."); | throw new InvalidOperationException("Only the author of a message may modify the message content, embed, or allowed mentions."); | ||||
var embed = args.Embed; | |||||
var embeds = args.Embeds; | |||||
bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content); | bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content); | ||||
bool hasEmbed = args.Embeds.IsSpecified ? args.Embeds.Value != null : msg.Embeds.Any(); | |||||
if (!hasText && !hasEmbed) | |||||
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)); | Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); | ||||
if (args.AllowedMentions.IsSpecified) | if (args.AllowedMentions.IsSpecified) | ||||
@@ -61,22 +66,24 @@ namespace Discord.Rest | |||||
} | } | ||||
} | } | ||||
var embeds = new List<API.Embed>(); | |||||
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null; | |||||
if (args.Embed.IsSpecified) | |||||
if (embed.IsSpecified && embed.Value != null) | |||||
{ | { | ||||
embeds.Add(args.Embed.Value.ToModel()); | |||||
apiEmbeds.Add(embed.Value.ToModel()); | |||||
} | } | ||||
if (args.Embeds.IsSpecified) | |||||
if (embeds.IsSpecified && embeds.Value != null) | |||||
{ | { | ||||
embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel())); | |||||
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); | |||||
} | } | ||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
var apiArgs = new ModifyMessageParams | var apiArgs = new ModifyMessageParams | ||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
Embeds = embeds.ToArray(), | |||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | ||||
Flags = args.Flags, | Flags = args.Flags, | ||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, | ||||
@@ -90,7 +97,13 @@ namespace Discord.Rest | |||||
var args = new MessageProperties(); | var args = new MessageProperties(); | ||||
func(args); | func(args); | ||||
if (args.Content.IsSpecified && string.IsNullOrEmpty(args.Content.Value) && args.Embeds.IsSpecified && args.Embeds.Value == null) | |||||
var embed = args.Embed; | |||||
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); | |||||
if (!hasText && !hasEmbeds) | |||||
Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); | Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); | ||||
if (args.AllowedMentions.IsSpecified) | if (args.AllowedMentions.IsSpecified) | ||||
@@ -117,22 +130,24 @@ namespace Discord.Rest | |||||
} | } | ||||
} | } | ||||
var embeds = new List<API.Embed>(); | |||||
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null; | |||||
if (args.Embed.IsSpecified) | |||||
if (embed.IsSpecified && embed.Value != null) | |||||
{ | { | ||||
embeds.Add(args.Embed.Value.ToModel()); | |||||
apiEmbeds.Add(embed.Value.ToModel()); | |||||
} | } | ||||
if (args.Embeds.IsSpecified) | |||||
if (embeds.IsSpecified && embeds.Value != null) | |||||
{ | { | ||||
embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel())); | |||||
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); | |||||
} | } | ||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
var apiArgs = new API.Rest.ModifyMessageParams | var apiArgs = new API.Rest.ModifyMessageParams | ||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
Embeds = embeds.ToArray(), | |||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create<MessageFlags?>(), | Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create<MessageFlags?>(), | ||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create<API.AllowedMentions>(), | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create<API.AllowedMentions>(), | ||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, | ||||
@@ -4,12 +4,13 @@ using System.Threading.Tasks; | |||||
using Model = Discord.API.Interaction; | using Model = Discord.API.Interaction; | ||||
using DataModel = Discord.API.MessageComponentInteractionData; | using DataModel = Discord.API.MessageComponentInteractionData; | ||||
using Discord.Rest; | using Discord.Rest; | ||||
using System.Collections.Generic; | |||||
namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
{ | { | ||||
/// <summary> | |||||
/// Represents a Websocket-based interaction type for Message Components. | |||||
/// </summary> | |||||
/// <summary> | |||||
/// Represents a Websocket-based interaction type for Message Components. | |||||
/// </summary> | |||||
public class SocketMessageComponent : SocketInteraction | public class SocketMessageComponent : SocketInteraction | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -149,8 +150,28 @@ namespace Discord.WebSocket | |||||
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); | Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); | ||||
} | } | ||||
if (args.Embeds.IsSpecified) | |||||
Preconditions.AtMost(args.Embeds.Value?.Length ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
var embed = args.Embed; | |||||
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(); | |||||
if (!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; | |||||
if (embed.IsSpecified && embed.Value != null) | |||||
{ | |||||
apiEmbeds.Add(embed.Value.ToModel()); | |||||
} | |||||
if (embeds.IsSpecified && embeds.Value != null) | |||||
{ | |||||
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); | |||||
} | |||||
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); | |||||
// check that user flag and user Id list are exclusive, same with role flag and role Id list | // check that user flag and user Id list are exclusive, same with role flag and role Id list | ||||
if (args.AllowedMentions.IsSpecified && args.AllowedMentions.Value != null && args.AllowedMentions.Value.AllowedTypes.HasValue) | if (args.AllowedMentions.IsSpecified && args.AllowedMentions.Value != null && args.AllowedMentions.Value.AllowedTypes.HasValue) | ||||
@@ -176,7 +197,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
Content = args.Content, | Content = args.Content, | ||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified, | AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified, | ||||
Embeds = args.Embeds.IsSpecified ? args.Embeds.Value?.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, | |||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified, | |||||
Components = args.Components.IsSpecified | Components = args.Components.IsSpecified | ||||
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() | ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() | ||||
: Optional<API.ActionRowComponent[]>.Unspecified, | : Optional<API.ActionRowComponent[]>.Unspecified, | ||||