From 69c734808d8d4a71b4c81696adf36ee185b77eb9 Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 28 May 2021 13:06:52 -0500 Subject: [PATCH 1/4] Initial pass at making slash commands respond as expected --- .../API/Common/ApplicationCommandInteractionData.cs | 6 +----- .../Common/ApplicationCommandInteractionDataOption.cs | 6 +----- .../Interaction/Slash Commands/SocketSlashCommand.cs | 7 ++----- .../Interaction/Slash Commands/SocketSlashCommandData.cs | 9 +++------ .../Slash Commands/SocketSlashCommandDataOption.cs | 9 +++------ 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs index b421edf6f..118dcc0f0 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs @@ -1,9 +1,5 @@ using Newtonsoft.Json; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Discord.API { @@ -16,6 +12,6 @@ namespace Discord.API public string Name { get; set; } [JsonProperty("options")] - public Optional Options { get; set; } + public List Options { get; set; } = new(); } } diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs index 84f2e3f7a..33d04800f 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs @@ -1,9 +1,5 @@ using Newtonsoft.Json; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Discord.API { @@ -16,6 +12,6 @@ namespace Discord.API public Optional Value { get; set; } [JsonProperty("options")] - public Optional> Options { get; set; } + public List Options { get; set; } = new(); } } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs index da94c4625..c3f760ebc 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs @@ -1,12 +1,9 @@ using Discord.Rest; using Newtonsoft.Json.Linq; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; -using Model = Discord.API.Gateway.InteractionCreated; using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Gateway.InteractionCreated; namespace Discord.WebSocket { @@ -40,7 +37,7 @@ namespace Discord.WebSocket (model.Data.Value as JToken).ToObject() : null; - this.Data.Update(data, this.Guild.Id); + this.Data.Update(data, model.GuildId); base.Update(model); } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs index 098d81b86..eebc18a9a 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs @@ -1,9 +1,6 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Model = Discord.API.ApplicationCommandInteractionData; namespace Discord.WebSocket @@ -14,7 +11,7 @@ namespace Discord.WebSocket public string Name { get; private set; } /// - /// The 's recieved with this interaction. + /// The 's received with this interaction. /// public IReadOnlyCollection Options { get; private set; } @@ -37,8 +34,8 @@ namespace Discord.WebSocket this.Name = model.Name; this.guildId = guildId; - this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => new SocketSlashCommandDataOption(x, this.Discord, guildId)).ToImmutableArray() + this.Options = model.Options.Any() + ? model.Options.Select(x => new SocketSlashCommandDataOption(x, this.Discord, guildId)).ToImmutableArray() : null; } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs index 89f1443be..e3f7d520d 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs @@ -1,9 +1,6 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Model = Discord.API.ApplicationCommandInteractionDataOption; namespace Discord.WebSocket @@ -20,7 +17,7 @@ namespace Discord.WebSocket public object Value { get; private set; } /// - /// The sub command options recieved for this sub command group. + /// The sub command options received for this sub command group. /// public IReadOnlyCollection Options { get; private set; } @@ -35,8 +32,8 @@ namespace Discord.WebSocket this.discord = discord; this.guild = guild; - this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => new SocketSlashCommandDataOption(x, discord, guild)).ToImmutableArray() + this.Options = model.Options.Any() + ? model.Options.Select(x => new SocketSlashCommandDataOption(x, discord, guild)).ToImmutableArray() : null; } From 1a2753d25771b1e699ab288722cf108f5479d66b Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 28 May 2021 13:30:51 -0500 Subject: [PATCH 2/4] Addition of required library missed in merge --- .../Entities/Interaction/Slash Commands/SocketSlashCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs index 69b18c44d..72e8a0d6a 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs @@ -1,6 +1,7 @@ using Discord.Rest; using Newtonsoft.Json.Linq; using System; +using System.Linq; using System.Threading.Tasks; using DataModel = Discord.API.ApplicationCommandInteractionData; using Model = Discord.API.Gateway.InteractionCreated; From 142f9cc485f918ad7e4d59f5fe9d3a6b87972eb3 Mon Sep 17 00:00:00 2001 From: d4n3436 Date: Fri, 28 May 2021 17:04:52 -0500 Subject: [PATCH 3/4] Add missing bucket ids and RequestOptions in GetInteractionResponse() --- src/Discord.Net.Rest/DiscordRestApiClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index da3410807..55b482aaf 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -956,7 +956,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", $"webhooks/{this.CurrentUserId}/{interactionToken}/messages/@original").ConfigureAwait(false); + return await SendAsync("GET", $"webhooks/{this.CurrentUserId}/{interactionToken}/messages/@original", new BucketIds(), options: options).ConfigureAwait(false); } public async Task ModifyInteractionResponse(ModifyInteractionResponseParams args, string interactionToken, RequestOptions options = null) { From 98027c387ce8319f501e31530ca8ed07d4bd0e58 Mon Sep 17 00:00:00 2001 From: d4n3436 Date: Fri, 28 May 2021 17:29:18 -0500 Subject: [PATCH 4/4] Add lambda --- src/Discord.Net.Rest/DiscordRestApiClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 55b482aaf..9f2e90730 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -956,7 +956,7 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); - return await SendAsync("GET", $"webhooks/{this.CurrentUserId}/{interactionToken}/messages/@original", new BucketIds(), options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"webhooks/{this.CurrentUserId}/{interactionToken}/messages/@original", new BucketIds(), options: options).ConfigureAwait(false); } public async Task ModifyInteractionResponse(ModifyInteractionResponseParams args, string interactionToken, RequestOptions options = null) {