This reverts commit ba78e0c1f0.
This commit is contained in:
@@ -82,8 +82,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -91,7 +90,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -116,13 +115,6 @@ 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,
|
||||
@@ -130,8 +122,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = flags,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
@@ -157,8 +149,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -166,7 +157,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -176,28 +167,21 @@ 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 is { AllowedTypes: not null })
|
||||
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
|
||||
{
|
||||
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
|
||||
allowedMentions.UserIds is { Count: > 0 })
|
||||
allowedMentions.UserIds != null && allowedMentions.UserIds.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 is { Count: > 0 })
|
||||
allowedMentions.RoleIds != null && allowedMentions.RoleIds.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,
|
||||
@@ -207,8 +191,8 @@ namespace Discord.WebSocket
|
||||
AllowedMentions = allowedMentions?.ToModel(),
|
||||
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
|
||||
TTS = isTTS,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
}
|
||||
};
|
||||
@@ -266,13 +250,13 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var allowedMentions = args.AllowedMentions.Value;
|
||||
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users)
|
||||
&& allowedMentions.UserIds is { Count: > 0 })
|
||||
&& allowedMentions.UserIds != null && allowedMentions.UserIds.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 is { Count: > 0 })
|
||||
&& allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0)
|
||||
{
|
||||
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(args.AllowedMentions));
|
||||
}
|
||||
@@ -289,8 +273,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 => x.ToModel()).ToArray() ?? []
|
||||
: Optional<IMessageComponent[]>.Unspecified,
|
||||
? 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
|
||||
}
|
||||
};
|
||||
@@ -299,7 +283,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
else
|
||||
{
|
||||
var attachments = args.Attachments.Value?.ToArray() ?? [];
|
||||
var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty<FileAttachment>();
|
||||
|
||||
var response = new API.Rest.UploadInteractionFileParams(attachments)
|
||||
{
|
||||
@@ -308,8 +292,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 => x.ToModel()).ToArray() ?? []
|
||||
: Optional<IMessageComponent[]>.Unspecified,
|
||||
? 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
|
||||
};
|
||||
|
||||
@@ -337,13 +321,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -352,25 +335,19 @@ 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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
@@ -385,13 +362,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -409,24 +385,23 @@ namespace Discord.WebSocket
|
||||
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
|
||||
{
|
||||
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
|
||||
allowedMentions.UserIds is { Count: > 0 })
|
||||
allowedMentions.UserIds != null && allowedMentions.UserIds.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 is { Count: > 0 })
|
||||
allowedMentions.RoleIds != null && allowedMentions.RoleIds.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;
|
||||
|
||||
var flags = MessageFlags.None;
|
||||
|
||||
if (ephemeral)
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
Preconditions.ValidateMessageFlags(flags);
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
|
||||
{
|
||||
Flags = flags,
|
||||
@@ -434,7 +409,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
|
||||
@@ -90,13 +90,13 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
internal SocketMessageComponentData(IInteractableComponent component, DiscordSocketClient discord, ClientState state, SocketGuild guild, API.User dmUser)
|
||||
internal SocketMessageComponentData(IMessageComponent component, DiscordSocketClient discord, ClientState state, SocketGuild guild, API.User dmUser)
|
||||
{
|
||||
CustomId = component.CustomId;
|
||||
Type = component.Type;
|
||||
|
||||
Value = component.Type == ComponentType.TextInput
|
||||
? ((TextInputComponent)component).Value
|
||||
? (component as API.TextInputComponent).Value.Value
|
||||
: null;
|
||||
|
||||
if (component is API.SelectMenuComponent select)
|
||||
|
||||
@@ -79,8 +79,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -88,7 +87,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -112,12 +111,6 @@ 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())
|
||||
{
|
||||
@@ -126,8 +119,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = flags,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
@@ -143,7 +136,7 @@ namespace Discord.WebSocket
|
||||
HasResponded = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IDiscordInteraction.RespondAsync"/>
|
||||
/// <inheritdoc/>
|
||||
public override async Task RespondAsync(
|
||||
string text = null,
|
||||
Embed[] embeds = null,
|
||||
@@ -153,8 +146,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -162,7 +154,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -172,28 +164,21 @@ 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 is { AllowedTypes: not null })
|
||||
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
|
||||
{
|
||||
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) &&
|
||||
allowedMentions.UserIds is { Count: > 0 })
|
||||
allowedMentions.UserIds != null && allowedMentions.UserIds.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 is { Count: > 0 })
|
||||
allowedMentions.RoleIds != null && allowedMentions.RoleIds.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,
|
||||
@@ -203,8 +188,8 @@ namespace Discord.WebSocket
|
||||
AllowedMentions = allowedMentions?.ToModel(),
|
||||
Embeds = embeds.Select(x => x.ToModel()).ToArray(),
|
||||
TTS = isTTS,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
}
|
||||
};
|
||||
@@ -285,11 +270,9 @@ 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 => x.ToModel()).ToArray() ?? []
|
||||
: Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = args.Flags.IsSpecified
|
||||
? args.Flags.Value ?? Optional<MessageFlags>.Unspecified
|
||||
: Optional<MessageFlags>.Unspecified
|
||||
? 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
|
||||
}
|
||||
};
|
||||
|
||||
@@ -306,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,
|
||||
MessageComponents = args.Components.IsSpecified
|
||||
? args.Components.Value?.Components.Select(x => x.ToModel()).ToArray() ?? []
|
||||
: Optional<IMessageComponent[]>.Unspecified,
|
||||
? 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
|
||||
};
|
||||
|
||||
@@ -335,13 +318,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -350,24 +332,20 @@ 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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
@@ -382,13 +360,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -418,13 +395,11 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
|
||||
flags |= MessageFlags.ComponentsV2;
|
||||
var flags = MessageFlags.None;
|
||||
|
||||
if (ephemeral)
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
Preconditions.ValidateMessageFlags(flags);
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
|
||||
{
|
||||
Flags = flags,
|
||||
@@ -432,7 +407,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
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
|
||||
@@ -24,7 +26,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
CustomId = model.CustomId;
|
||||
Components = model.Components
|
||||
.SelectMany(x => x.Components.Select(y => y.ToEntity()).OfType<IInteractableComponent>())
|
||||
.SelectMany(x => x.Components)
|
||||
.Select(x => new SocketMessageComponentData(x, discord, state, guild, dmUser))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -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, MessageFlags flags = MessageFlags.None)
|
||||
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)
|
||||
=> 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, MessageFlags flags = MessageFlags.None)
|
||||
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)
|
||||
=> 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, MessageFlags flags = MessageFlags.None)
|
||||
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)
|
||||
=> 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, MessageFlags flags = MessageFlags.None)
|
||||
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)
|
||||
=> throw new NotSupportedException("Autocomplete interactions don't support this method!");
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -86,7 +85,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -111,13 +110,6 @@ 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,
|
||||
@@ -127,8 +119,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
}
|
||||
};
|
||||
@@ -191,8 +183,7 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
@@ -200,7 +191,7 @@ namespace Discord.WebSocket
|
||||
if (!InteractionHelper.CanSendResponse(this) && Discord.ResponseInternalTimeCheck)
|
||||
throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -225,13 +216,6 @@ 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,
|
||||
@@ -239,8 +223,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 = flags,
|
||||
MessageComponents = components?.Components.Select(x => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Flags = ephemeral ? MessageFlags.Ephemeral : Optional<MessageFlags>.Unspecified,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
@@ -266,13 +250,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -281,24 +264,19 @@ 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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified,
|
||||
Flags = flags,
|
||||
Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
|
||||
if (ephemeral)
|
||||
args.Flags = MessageFlags.Ephemeral;
|
||||
|
||||
return InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options);
|
||||
}
|
||||
|
||||
@@ -313,13 +291,12 @@ namespace Discord.WebSocket
|
||||
MessageComponent components = null,
|
||||
Embed embed = null,
|
||||
RequestOptions options = null,
|
||||
PollProperties poll = null,
|
||||
MessageFlags flags = MessageFlags.None)
|
||||
PollProperties poll = null)
|
||||
{
|
||||
if (!IsValidToken)
|
||||
throw new InvalidOperationException("Interaction token is no longer valid");
|
||||
|
||||
embeds ??= [];
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
embeds = new[] { embed }.Concat(embeds).ToArray();
|
||||
|
||||
@@ -349,13 +326,11 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
|
||||
if (components?.Components?.Any(x => x.Type != ComponentType.ActionRow) ?? false)
|
||||
flags |= MessageFlags.ComponentsV2;
|
||||
var flags = MessageFlags.None;
|
||||
|
||||
if (ephemeral)
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
|
||||
Preconditions.ValidateMessageFlags(flags);
|
||||
|
||||
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray())
|
||||
{
|
||||
Flags = flags,
|
||||
@@ -363,7 +338,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 => x.ToModel()).ToArray() ?? Optional<IMessageComponent[]>.Unspecified,
|
||||
MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Poll = poll?.ToModel() ?? Optional<CreatePollParams>.Unspecified
|
||||
};
|
||||
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
|
||||
|
||||
@@ -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, MessageFlags flags = MessageFlags.None);
|
||||
bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
|
||||
|
||||
/// <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, MessageFlags flags = MessageFlags.None)
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
|
||||
{
|
||||
using (var file = new FileAttachment(fileStream, fileName))
|
||||
{
|
||||
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags = MessageFlags.None)
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
|
||||
{
|
||||
using (var file = new FileAttachment(filePath, fileName))
|
||||
{
|
||||
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags = MessageFlags.None)
|
||||
=> RespondWithFilesAsync([attachment], text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
|
||||
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);
|
||||
|
||||
/// <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, MessageFlags flags = MessageFlags.None);
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
|
||||
|
||||
/// <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, MessageFlags flags = MessageFlags.None);
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
|
||||
|
||||
/// <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, MessageFlags flags = MessageFlags.None)
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
|
||||
{
|
||||
using (var file = new FileAttachment(fileStream, fileName))
|
||||
{
|
||||
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags = MessageFlags.None)
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
|
||||
{
|
||||
using (var file = new FileAttachment(filePath, fileName))
|
||||
{
|
||||
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags = MessageFlags.None)
|
||||
=> FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
|
||||
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);
|
||||
|
||||
/// <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, MessageFlags flags = MessageFlags.None);
|
||||
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
|
||||
|
||||
/// <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, MessageFlags flags)
|
||||
=> await RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
Embed embed, RequestOptions options, PollProperties poll)
|
||||
=> await RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags)
|
||||
=> await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
MessageComponent components, Embed embed, RequestOptions options, PollProperties poll)
|
||||
=> await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags)
|
||||
=> await FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
|
||||
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);
|
||||
#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, MessageFlags flags)
|
||||
=> await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).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)
|
||||
=> await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags)
|
||||
=> await FollowupWithFileAsync(filePath, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).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)
|
||||
=> await FollowupWithFileAsync(filePath, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).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, MessageFlags flags)
|
||||
=> await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).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)
|
||||
=> await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Model = Discord.API.Message;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
@@ -65,8 +64,8 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public MessageReference Reference { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IMessage.Components"/>
|
||||
public IReadOnlyCollection<IMessageComponent> Components { get; private set; }
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<ActionRowComponent> Components { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interaction this message is a response to.
|
||||
@@ -214,9 +213,62 @@ namespace Discord.WebSocket
|
||||
};
|
||||
}
|
||||
|
||||
Components = model.Components.IsSpecified
|
||||
? model.Components.Value.Select(x => x.ToEntity()).ToImmutableArray()
|
||||
: [];
|
||||
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>();
|
||||
|
||||
if (model.UserMentions.IsSpecified)
|
||||
{
|
||||
@@ -281,7 +333,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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user