* Error handling on URL additions in embeds and components. * Wording on exception comment * Wording on exceptions * changed IsWellFormatted to validating urls start with protocol. May not keep all url validation, may just keep image-based url validation as those definitely only require http/s. * Helper utility made for url validation * Add embed for single embed to Respond/FollowupAsync * xml * Removed trailing spaces. Clarified params in SocketInteractions. Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>pull/1923/head
@@ -75,10 +75,13 @@ namespace Discord.WebSocket | |||||
bool ephemeral = false, | bool ephemeral = false, | ||||
AllowedMentions allowedMentions = null, | AllowedMentions allowedMentions = null, | ||||
RequestOptions options = null, | RequestOptions options = null, | ||||
MessageComponent component = null) | |||||
MessageComponent component = null, | |||||
Embed embed = null) | |||||
{ | { | ||||
if (!IsValidToken) | if (!IsValidToken) | ||||
throw new InvalidOperationException("Interaction token is no longer valid"); | throw new InvalidOperationException("Interaction token is no longer valid"); | ||||
if (embeds == null && embed != null) | |||||
embeds = new[] { embed }; | |||||
if (Discord.AlwaysAcknowledgeInteractions) | if (Discord.AlwaysAcknowledgeInteractions) | ||||
{ | { | ||||
@@ -106,7 +109,6 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
var response = new API.InteractionResponse | var response = new API.InteractionResponse | ||||
{ | { | ||||
Type = InteractionResponseType.ChannelMessageWithSource, | Type = InteractionResponseType.ChannelMessageWithSource, | ||||
@@ -193,11 +195,14 @@ namespace Discord.WebSocket | |||||
bool ephemeral = false, | bool ephemeral = false, | ||||
AllowedMentions allowedMentions = null, | AllowedMentions allowedMentions = null, | ||||
RequestOptions options = null, | RequestOptions options = null, | ||||
MessageComponent component = null) | |||||
MessageComponent component = null, | |||||
Embed embed = null) | |||||
{ | { | ||||
if (!IsValidToken) | if (!IsValidToken) | ||||
throw new InvalidOperationException("Interaction token is no longer valid"); | throw new InvalidOperationException("Interaction token is no longer valid"); | ||||
if (embeds == null && embed != null) | |||||
embeds = new[] { embed }; | |||||
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); | Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); | ||||
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); | Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); | ||||
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); | Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); | ||||
@@ -57,11 +57,15 @@ namespace Discord.WebSocket | |||||
bool ephemeral = false, | bool ephemeral = false, | ||||
AllowedMentions allowedMentions = null, | AllowedMentions allowedMentions = null, | ||||
RequestOptions options = null, | RequestOptions options = null, | ||||
MessageComponent component = null) | |||||
MessageComponent component = null, | |||||
Embed embed = null) | |||||
{ | { | ||||
if (!IsValidToken) | if (!IsValidToken) | ||||
throw new InvalidOperationException("Interaction token is no longer valid"); | throw new InvalidOperationException("Interaction token is no longer valid"); | ||||
if (embeds == null && embed != null) | |||||
embeds = new[] { embed }; | |||||
if (Discord.AlwaysAcknowledgeInteractions) | if (Discord.AlwaysAcknowledgeInteractions) | ||||
{ | { | ||||
await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, options, component); | await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, options, component); | ||||
@@ -87,8 +91,7 @@ namespace Discord.WebSocket | |||||
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); | throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); | ||||
} | } | ||||
} | } | ||||
var response = new API.InteractionResponse | var response = new API.InteractionResponse | ||||
{ | { | ||||
Type = InteractionResponseType.ChannelMessageWithSource, | Type = InteractionResponseType.ChannelMessageWithSource, | ||||
@@ -116,11 +119,14 @@ namespace Discord.WebSocket | |||||
bool ephemeral = false, | bool ephemeral = false, | ||||
AllowedMentions allowedMentions = null, | AllowedMentions allowedMentions = null, | ||||
RequestOptions options = null, | RequestOptions options = null, | ||||
MessageComponent component = null) | |||||
MessageComponent component = null, | |||||
Embed embed = null) | |||||
{ | { | ||||
if (!IsValidToken) | if (!IsValidToken) | ||||
throw new InvalidOperationException("Interaction token is no longer valid"); | throw new InvalidOperationException("Interaction token is no longer valid"); | ||||
if (embeds == null && embed != null) | |||||
embeds = new[] { embed }; | |||||
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); | Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); | ||||
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); | Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); | ||||
Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); | Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed."); | ||||
@@ -96,7 +96,7 @@ namespace Discord.WebSocket | |||||
/// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>. | /// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>. | ||||
/// <para> | /// <para> | ||||
/// If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use | /// If you have <see cref="DiscordSocketConfig.AlwaysAcknowledgeInteractions"/> set to <see langword="true"/>, You should use | ||||
/// <see cref="FollowupAsync(Discord.Embed[],string,bool,bool,Discord.AllowedMentions,Discord.RequestOptions,Discord.MessageComponent)"/> instead. | |||||
/// <see cref="FollowupAsync"/> instead. | |||||
/// </para> | /// </para> | ||||
/// </summary> | /// </summary> | ||||
/// <param name="text">The text of the message to be sent.</param> | /// <param name="text">The text of the message to be sent.</param> | ||||
@@ -106,10 +106,11 @@ namespace Discord.WebSocket | |||||
/// <param name="allowedMentions">The allowed mentions for this response.</param> | /// <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
/// <param name="options">The request options for this response.</param> | /// <param name="options">The request options for this response.</param> | ||||
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | ||||
/// <param name="embed">A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.</param> | |||||
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception> | /// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception> | ||||
public abstract Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, | public abstract Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, | ||||
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null); | |||||
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | |||||
/// <summary> | /// <summary> | ||||
/// Sends a followup message for this interaction. | /// Sends a followup message for this interaction. | ||||
@@ -121,11 +122,12 @@ namespace Discord.WebSocket | |||||
/// <param name="allowedMentions">The allowed mentions for this response.</param> | /// <param name="allowedMentions">The allowed mentions for this response.</param> | ||||
/// <param name="options">The request options for this response.</param> | /// <param name="options">The request options for this response.</param> | ||||
/// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response</param> | ||||
/// <param name="embed">A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.</param> | |||||
/// <returns> | /// <returns> | ||||
/// The sent message. | /// The sent message. | ||||
/// </returns> | /// </returns> | ||||
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||||
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null); | |||||
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, | |||||
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null); | |||||
/// <summary> | /// <summary> | ||||
/// Gets the original response for this interaction. | /// Gets the original response for this interaction. | ||||