Reapply "[Feature] Components V2 (#3065)" (#3100) (#3104)

This reverts commit d27bb49b2d.
This commit is contained in:
Mihail Gribkov
2025-04-27 00:31:08 +03:00
committed by GitHub
parent 25230f31cd
commit 8686102d87
102 changed files with 2852 additions and 692 deletions

View File

@@ -82,7 +82,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -90,7 +91,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -115,6 +116,13 @@ namespace Discord.WebSocket
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.Rest.UploadInteractionFileParams(attachments?.ToArray())
{
Type = InteractionResponseType.ChannelMessageWithSource,
@@ -122,8 +130,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions != null ? allowedMentions?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
IsTTS = isTTS,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Flags = flags,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
@@ -149,7 +157,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -157,7 +166,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -167,21 +176,28 @@ namespace Discord.WebSocket
Preconditions.ValidatePoll(poll);
// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
if (allowedMentions is { AllowedTypes: not null })
{
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
allowedMentions.UserIds is { Count: > 0 })
{
throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
}
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
allowedMentions.RoleIds is { Count: > 0 })
{
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.InteractionResponse
{
Type = InteractionResponseType.ChannelMessageWithSource,
@@ -191,8 +207,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions?.ToModel(),
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
TTS = isTTS,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = flags,
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
}
};
@@ -250,13 +266,13 @@ namespace Discord.WebSocket
{
var allowedMentions = args.AllowedMentions.Value;
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users)
&& allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
&& allowedMentions.UserIds is { Count: > 0 })
{
throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(args.AllowedMentions));
}
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles)
&& allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
&& allowedMentions.RoleIds is { Count: > 0 })
{
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(args.AllowedMentions));
}
@@ -273,8 +289,8 @@ namespace Discord.WebSocket
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
Components = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
: Optional<API.ActionRowComponent[]>.Unspecified,
? args.Components.Value?.Components.Select(x => x.ToModel()).ToArray() ?? []
: Optional<IMessageComponent[]>.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
}
};
@@ -283,7 +299,7 @@ namespace Discord.WebSocket
}
else
{
var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty<FileAttachment>();
var attachments = args.Attachments.Value?.ToArray() ?? [];
var response = new API.Rest.UploadInteractionFileParams(attachments)
{
@@ -292,8 +308,8 @@ namespace Discord.WebSocket
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
MessageComponents = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
: Optional<API.ActionRowComponent[]>.Unspecified,
? args.Components.Value?.Components.Select(x => x.ToModel()).ToArray() ?? []
: Optional<IMessageComponent[]>.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
};
@@ -321,12 +337,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -335,19 +352,25 @@ namespace Discord.WebSocket
Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.ValidatePoll(poll);
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.CreateWebhookMessageParams
{
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
IsTTS = isTTS,
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified,
Flags = flags,
};
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
}
@@ -362,12 +385,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -385,23 +409,24 @@ namespace Discord.WebSocket
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
{
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
allowedMentions.UserIds is { Count: > 0 })
{
throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
}
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
allowedMentions.RoleIds is { Count: > 0 })
{
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
}
}
var flags = MessageFlags.None;
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
{
Flags = flags,
@@ -409,7 +434,7 @@ namespace Discord.WebSocket
IsTTS = isTTS,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);

View File

@@ -90,13 +90,13 @@ namespace Discord.WebSocket
}
}
internal SocketMessageComponentData(IMessageComponent component, DiscordSocketClient discord, ClientState state, SocketGuild guild, API.User dmUser)
internal SocketMessageComponentData(IInteractableComponent component, DiscordSocketClient discord, ClientState state, SocketGuild guild, API.User dmUser)
{
CustomId = component.CustomId;
Type = component.Type;
Value = component.Type == ComponentType.TextInput
? (component as API.TextInputComponent).Value.Value
? ((TextInputComponent)component).Value
: null;
if (component is API.SelectMenuComponent select)

View File

@@ -79,7 +79,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -87,7 +88,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -111,6 +112,12 @@ namespace Discord.WebSocket
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.Rest.UploadInteractionFileParams(attachments?.ToArray())
{
@@ -119,8 +126,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions != null ? allowedMentions?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
IsTTS = isTTS,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Flags = flags,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
@@ -136,7 +143,7 @@ namespace Discord.WebSocket
HasResponded = true;
}
/// <inheritdoc/>
/// <inheritdoc cref="IDiscordInteraction.RespondAsync"/>
public override async Task RespondAsync(
string text = null,
Embed[] embeds = null,
@@ -146,7 +153,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -154,7 +162,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -164,21 +172,28 @@ namespace Discord.WebSocket
Preconditions.ValidatePoll(poll);
// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
if (allowedMentions is { AllowedTypes: not null })
{
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0)
allowedMentions.UserIds is { Count: > 0 })
{
throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions));
}
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) &&
allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
allowedMentions.RoleIds is { Count: > 0 })
{
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions));
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.InteractionResponse
{
Type = InteractionResponseType.ChannelMessageWithSource,
@@ -188,8 +203,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions?.ToModel(),
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
TTS = isTTS,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = flags,
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
}
};
@@ -270,9 +285,11 @@ namespace Discord.WebSocket
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
Components = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
: Optional<API.ActionRowComponent[]>.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
? args.Components.Value?.Components.Select(x => x.ToModel()).ToArray() ?? []
: Optional<IMessageComponent[]>.Unspecified,
Flags = args.Flags.IsSpecified
? args.Flags.Value ?? Optional<MessageFlags>.Unspecified
: Optional<MessageFlags>.Unspecified
}
};
@@ -289,8 +306,8 @@ namespace Discord.WebSocket
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
MessageComponents = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
: Optional<API.ActionRowComponent[]>.Unspecified,
? args.Components.Value?.Components.Select(x => x.ToModel()).ToArray() ?? []
: Optional<IMessageComponent[]>.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
};
@@ -318,12 +335,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -332,20 +350,24 @@ namespace Discord.WebSocket
Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.ValidatePoll(poll);
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.CreateWebhookMessageParams
{
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
IsTTS = isTTS,
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Flags = flags,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
}
@@ -360,12 +382,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -395,11 +418,13 @@ namespace Discord.WebSocket
}
}
var flags = MessageFlags.None;
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
{
Flags = flags,
@@ -407,7 +432,7 @@ namespace Discord.WebSocket
IsTTS = isTTS,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);

View File

@@ -1,8 +1,6 @@
using System;
using Discord.Rest;
using System.Collections.Generic;
using System.Linq;
using DataModel = Discord.API.MessageComponentInteractionData;
using InterationModel = Discord.API.Interaction;
using Model = Discord.API.ModalInteractionData;
namespace Discord.WebSocket
@@ -26,7 +24,7 @@ namespace Discord.WebSocket
{
CustomId = model.CustomId;
Components = model.Components
.SelectMany(x => x.Components)
.SelectMany(x => x.Components.Select(y => y.ToEntity()).OfType<IInteractableComponent>())
.Select(x => new SocketMessageComponentData(x, discord, state, guild, dmUser))
.ToArray();
}

View File

@@ -91,15 +91,15 @@ namespace Discord.WebSocket
/// </returns>
public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result)
=> RespondAsync(result, options);
public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
public override Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
public override Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
public override Task<RestFollowupMessage> FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
public override Task<RestFollowupMessage> FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
public override Task DeferAsync(bool ephemeral = false, RequestOptions options = null)
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
public override Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
public override Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
/// <inheritdoc/>

View File

@@ -77,7 +77,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -85,7 +86,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -110,6 +111,13 @@ namespace Discord.WebSocket
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.InteractionResponse
{
Type = InteractionResponseType.ChannelMessageWithSource,
@@ -119,8 +127,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
TTS = isTTS,
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Flags = flags,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
}
};
@@ -183,7 +191,8 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
@@ -191,7 +200,7 @@ namespace Discord.WebSocket
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -216,6 +225,13 @@ namespace Discord.WebSocket
}
}
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var response = new API.Rest.UploadInteractionFileParams(attachments?.ToArray())
{
Type = InteractionResponseType.ChannelMessageWithSource,
@@ -223,8 +239,8 @@ namespace Discord.WebSocket
AllowedMentions = allowedMentions != null ? allowedMentions?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
IsTTS = isTTS,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Flags = flags,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
@@ -250,12 +266,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -264,19 +281,24 @@ namespace Discord.WebSocket
Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.ValidatePoll(poll);
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.CreateWebhookMessageParams
{
Content = text ?? Optional<string>.Unspecified,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
IsTTS = isTTS,
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified,
Flags = flags,
};
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
}
@@ -291,12 +313,13 @@ namespace Discord.WebSocket
MessageComponent components = null,
Embed embed = null,
RequestOptions options = null,
PollProperties poll = null)
PollProperties poll = null,
MessageFlags flags = MessageFlags.None)
{
if (!IsValidToken)
throw new InvalidOperationException("Interaction token is no longer valid");
embeds ??= Array.Empty<Embed>();
embeds ??= [];
if (embed != null)
embeds = new[] { embed }.Concat(embeds).ToArray();
@@ -326,11 +349,13 @@ namespace Discord.WebSocket
}
}
var flags = MessageFlags.None;
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
flags |= MessageFlags.ComponentsV2;
if (ephemeral)
flags |= MessageFlags.Ephemeral;
Preconditions.ValidateMessageFlags(flags);
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
{
Flags = flags,
@@ -338,7 +363,7 @@ namespace Discord.WebSocket
IsTTS = isTTS,
Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified,
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
};
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);

View File

@@ -216,7 +216,7 @@ namespace Discord.WebSocket
/// <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>
public abstract Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false,
bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
/// <summary>
/// Responds to this interaction with a file attachment.
@@ -237,11 +237,11 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
{
using (var file = new FileAttachment(fileStream, fileName))
{
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
}
}
@@ -264,11 +264,11 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public async Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
{
using (var file = new FileAttachment(filePath, fileName))
{
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
}
}
@@ -290,8 +290,8 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
=> RespondWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll);
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> RespondWithFilesAsync([attachment], text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
/// <summary>
/// Responds to this interaction with a collection of file attachments.
@@ -311,7 +311,7 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public abstract Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
/// <summary>
/// Sends a followup message for this interaction.
@@ -329,7 +329,7 @@ namespace Discord.WebSocket
/// The sent message.
/// </returns>
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
/// <summary>
/// Sends a followup message for this interaction.
@@ -349,11 +349,11 @@ namespace Discord.WebSocket
/// The sent message.
/// </returns>
public async Task<RestFollowupMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
{
using (var file = new FileAttachment(fileStream, fileName))
{
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
}
}
@@ -375,11 +375,11 @@ namespace Discord.WebSocket
/// The sent message.
/// </returns>
public async Task<RestFollowupMessage> FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
{
using (var file = new FileAttachment(filePath, fileName))
{
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
}
}
@@ -401,8 +401,8 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public Task<RestFollowupMessage> FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
=> FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll);
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
=> FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
/// <summary>
/// Sends a followup message for this interaction.
@@ -422,7 +422,7 @@ namespace Discord.WebSocket
/// contains the sent message.
/// </returns>
public abstract Task<RestFollowupMessage> FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
/// <summary>
/// Gets the original response for this interaction.
@@ -509,26 +509,26 @@ namespace Discord.WebSocket
=> await ModifyOriginalResponseAsync(func, options).ConfigureAwait(false);
/// <inheritdoc/>
async Task IDiscordInteraction.RespondAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components,
Embed embed, RequestOptions options, PollProperties poll)
=> await RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
/// <inheritdoc/>
async Task<IUserMessage> IDiscordInteraction.FollowupAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions,
MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
=> await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
MessageComponent components, Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
/// <inheritdoc/>
async Task<IUserMessage> IDiscordInteraction.FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text, Embed[] embeds, bool isTTS,
bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
=> await FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
#if NETCOREAPP3_0_OR_GREATER != true
/// <inheritdoc/>
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(Stream fileStream, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
=> await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(Stream fileStream, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
/// <inheritdoc/>
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(string filePath, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
=> await FollowupWithFileAsync(filePath, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(string filePath, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await FollowupWithFileAsync(filePath, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
/// <inheritdoc/>
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(FileAttachment attachment, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
=> await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
async Task<IUserMessage> IDiscordInteraction.FollowupWithFileAsync(FileAttachment attachment, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options, PollProperties poll, MessageFlags flags)
=> await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
#endif
#endregion
}

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Model = Discord.API.Message;
namespace Discord.WebSocket
@@ -64,8 +65,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public MessageReference Reference { get; private set; }
/// <inheritdoc/>
public IReadOnlyCollection<ActionRowComponent> Components { get; private set; }
/// <inheritdoc cref="IMessage.Components"/>
public IReadOnlyCollection<IMessageComponent> Components { get; private set; }
/// <summary>
/// Gets the interaction this message is a response to.
@@ -213,62 +214,9 @@ namespace Discord.WebSocket
};
}
if (model.Components.IsSpecified)
{
Components = model.Components.Value.Where(x => x.Type is ComponentType.ActionRow)
.Select(x => new ActionRowComponent(((API.ActionRowComponent)x).Components.Select<IMessageComponent, IMessageComponent>(y =>
{
switch (y.Type)
{
case ComponentType.Button:
{
var parsed = (API.ButtonComponent)y;
return new Discord.ButtonComponent(
parsed.Style,
parsed.Label.GetValueOrDefault(),
parsed.Emote.IsSpecified
? parsed.Emote.Value.Id.HasValue
? new Emote(parsed.Emote.Value.Id.Value, parsed.Emote.Value.Name, parsed.Emote.Value.Animated.GetValueOrDefault())
: new Emoji(parsed.Emote.Value.Name)
: null,
parsed.CustomId.GetValueOrDefault(),
parsed.Url.GetValueOrDefault(),
parsed.Disabled.GetValueOrDefault(),
parsed.SkuId.ToNullable());
}
case ComponentType.SelectMenu:
{
var parsed = (API.SelectMenuComponent)y;
return new SelectMenuComponent(
parsed.CustomId,
parsed.Options.Select(z => new SelectMenuOption(
z.Label,
z.Value,
z.Description.GetValueOrDefault(),
z.Emoji.IsSpecified
? z.Emoji.Value.Id.HasValue
? new Emote(z.Emoji.Value.Id.Value, z.Emoji.Value.Name, z.Emoji.Value.Animated.GetValueOrDefault())
: new Emoji(z.Emoji.Value.Name)
: null,
z.Default.ToNullable())).ToList(),
parsed.Placeholder.GetValueOrDefault(),
parsed.MinValues,
parsed.MaxValues,
parsed.Disabled,
parsed.Type,
parsed.ChannelTypes.GetValueOrDefault(),
parsed.DefaultValues.IsSpecified
? parsed.DefaultValues.Value.Select(x => new SelectMenuDefaultValue(x.Id, x.Type))
: Array.Empty<SelectMenuDefaultValue>()
);
}
default:
return null;
}
}).ToList())).ToImmutableArray();
}
else
Components = new List<ActionRowComponent>();
Components = model.Components.IsSpecified
? model.Components.Value.Select(x => x.ToEntity()).ToImmutableArray()
: [];
if (model.UserMentions.IsSpecified)
{
@@ -333,7 +281,7 @@ namespace Discord.WebSocket
? new GuildProductPurchase(model.PurchaseNotification.Value.ProductPurchase.Value.ListingId, model.PurchaseNotification.Value.ProductPurchase.Value.ProductName)
: null);
}
if (model.Call.IsSpecified)
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
}