From 16f6a4c4822fd3e3e0f30466988a763075db3091 Mon Sep 17 00:00:00 2001 From: Cosma George Date: Wed, 10 Feb 2021 21:22:15 +0200 Subject: [PATCH] Fixed build errors and started an example project for development purposes and to be a starting-off point for newcomers to the slash command ecosystem, --- Discord.Net.sln | 28 +++++++++++++++++++ SlashCommandsExample/Program.cs | 17 +++++++++++ .../Properties/launchSettings.json | 7 +++++ .../SlashCommandsExample.csproj | 8 ++++++ .../Interactions/RestApplicationCommand.cs | 2 +- .../RestApplicationCommandOption.cs | 4 +-- .../Extensions/EntityExtensions.cs | 4 +-- .../SocketApplicationCommandOption.cs | 12 ++++---- .../Interaction/SocketInteractionData.cs | 2 +- .../SocketInteractionDataOption.cs | 2 +- 10 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 SlashCommandsExample/Program.cs create mode 100644 SlashCommandsExample/Properties/launchSettings.json create mode 100644 SlashCommandsExample/SlashCommandsExample.csproj diff --git a/Discord.Net.sln b/Discord.Net.sln index 084d8a834..95590e68b 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -42,6 +42,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Examples", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "idn", "samples\idn\idn.csproj", "{4A03840B-9EBE-47E3-89AB-E0914DF21AFB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlashCommandsExample", "SlashCommandsExample\SlashCommandsExample.csproj", "{2CB2A016-CCEB-4A67-BC7B-098F114D7C27}" + ProjectSection(ProjectDependencies) = postProject + {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} + {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} + {BFC6DC28-0351-4573-926A-D4124244C04F} = {BFC6DC28-0351-4573-926A-D4124244C04F} + {E169E15A-E82C-45BF-8C24-C2CADB7093AA} = {E169E15A-E82C-45BF-8C24-C2CADB7093AA} + {47820065-3CFB-401C-ACEA-862BD564A404} = {47820065-3CFB-401C-ACEA-862BD564A404} + {DBF8B16E-5967-4480-8EDE-15D98A0DF0C4} = {DBF8B16E-5967-4480-8EDE-15D98A0DF0C4} + {FC67057C-E92F-4E1C-98BE-46F839C8AD71} = {FC67057C-E92F-4E1C-98BE-46F839C8AD71} + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2} = {91E9E7BD-75C9-4E98-84AA-2C271922E5C2} + {688FD1D8-7F01-4539-B2E9-F473C5D699C7} = {688FD1D8-7F01-4539-B2E9-F473C5D699C7} + {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C} = {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C} + {BBA8E7FB-C834-40DC-822F-B112CB7F0140} = {BBA8E7FB-C834-40DC-822F-B112CB7F0140} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -232,6 +247,18 @@ Global {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x64.Build.0 = Release|Any CPU {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.ActiveCfg = Release|Any CPU {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.Build.0 = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|x64.ActiveCfg = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|x64.Build.0 = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|x86.ActiveCfg = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Debug|x86.Build.0 = Debug|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|Any CPU.Build.0 = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|x64.ActiveCfg = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|x64.Build.0 = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|x86.ActiveCfg = Release|Any CPU + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -251,6 +278,7 @@ Global {FC67057C-E92F-4E1C-98BE-46F839C8AD71} = {C7CF5621-7D36-433B-B337-5A2E3C101A71} {47820065-3CFB-401C-ACEA-862BD564A404} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {4A03840B-9EBE-47E3-89AB-E0914DF21AFB} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} + {2CB2A016-CCEB-4A67-BC7B-098F114D7C27} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D2404771-EEC8-45F2-9D71-F3373F6C1495} diff --git a/SlashCommandsExample/Program.cs b/SlashCommandsExample/Program.cs new file mode 100644 index 000000000..7863ea16f --- /dev/null +++ b/SlashCommandsExample/Program.cs @@ -0,0 +1,17 @@ +/* + * This project, is at this moment used for testing and debugging the new and experimental Slash Commands. + * After all testing has been done, and the project is ready to be integrated into the main Discord.Net ecosystem + * this project should be re-made into one that could be used as an example usage of the new Slash Command Service. + */ +using System; + +namespace SlashCommandsExample +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/SlashCommandsExample/Properties/launchSettings.json b/SlashCommandsExample/Properties/launchSettings.json new file mode 100644 index 000000000..4cfd08821 --- /dev/null +++ b/SlashCommandsExample/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "SlashCommandsExample": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/SlashCommandsExample/SlashCommandsExample.csproj b/SlashCommandsExample/SlashCommandsExample.csproj new file mode 100644 index 000000000..c73e0d169 --- /dev/null +++ b/SlashCommandsExample/SlashCommandsExample.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs index 67a530d50..d418ba213 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs @@ -60,7 +60,7 @@ namespace Discord.Rest this.Description = model.Description; this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => RestApplicationCommandOption.Create(x)).ToImmutableArray() + ? model.Options.Value.Select(x => RestApplicationCommandOption.Create(x)).ToImmutableArray().ToReadOnlyCollection() : null; } diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs index a8e37873e..89449722d 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs @@ -60,11 +60,11 @@ namespace Discord.Rest this.Required = model.Required.Value; this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => Create(x)).ToImmutableArray() + ? model.Options.Value.Select(x => Create(x)).ToImmutableArray().ToReadOnlyCollection() : null; this.Choices = model.Choices.IsSpecified - ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray() + ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray().ToReadOnlyCollection() : null; } diff --git a/src/Discord.Net.Rest/Extensions/EntityExtensions.cs b/src/Discord.Net.Rest/Extensions/EntityExtensions.cs index f8676c783..b20cc88d3 100644 --- a/src/Discord.Net.Rest/Extensions/EntityExtensions.cs +++ b/src/Discord.Net.Rest/Extensions/EntityExtensions.cs @@ -37,8 +37,8 @@ namespace Discord.Rest public static RoleTags ToEntity(this API.RoleTags model) { return new RoleTags( - model.BotId.IsSpecified ? model.BotId.Value : null, - model.IntegrationId.IsSpecified ? model.IntegrationId.Value : null, + model.BotId.IsSpecified ? model.BotId.Value : (ulong?)null, + model.IntegrationId.IsSpecified ? model.IntegrationId.Value : (ulong?)null, model.IsPremiumSubscriber.IsSpecified ? true : false); } public static API.Embed ToModel(this Embed entity) diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketApplicationCommandOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketApplicationCommandOption.cs index 0a90a8073..8f8222f0b 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketApplicationCommandOption.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketApplicationCommandOption.cs @@ -54,19 +54,19 @@ namespace Discord.WebSocket this.Default = model.Default.IsSpecified ? model.Default.Value - : null; + : (bool?)null; this.Required = model.Required.IsSpecified ? model.Required.Value - : null; + : (bool?)null; this.Choices = model.Choices.IsSpecified - ? model.Choices.Value.Select(x => SocketApplicationCommandChoice.Create(x)).ToImmutableArray() - : new ImmutableArray(); + ? model.Choices.Value.Select(x => SocketApplicationCommandChoice.Create(x)).ToImmutableArray().ToReadOnlyCollection() + : null; this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray() - : new ImmutableArray(); + ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray().ToReadOnlyCollection() + : null; } IReadOnlyCollection IApplicationCommandOption.Choices => Choices; diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionData.cs index eef7e5ab4..d30b64b3b 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionData.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionData.cs @@ -38,7 +38,7 @@ namespace Discord.WebSocket this.guildId = guildId; this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => new SocketInteractionDataOption(x, this.Discord, guildId)).ToImmutableArray() + ? model.Options.Value.Select(x => new SocketInteractionDataOption(x, this.Discord, guildId)).ToImmutableArray().ToReadOnlyCollection() : null; } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionDataOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionDataOption.cs index fea0bf3b6..683998272 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionDataOption.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteractionDataOption.cs @@ -36,7 +36,7 @@ namespace Discord.WebSocket this.guild = guild; this.Options = model.Options.IsSpecified - ? model.Options.Value.Select(x => new SocketInteractionDataOption(x, discord, guild)).ToImmutableArray() + ? model.Options.Value.Select(x => new SocketInteractionDataOption(x, discord, guild)).ToImmutableArray().ToReadOnlyCollection() : null; }