From 9358a0e0834297db61d589b26252aa144ebe646e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 06:28:31 +0200 Subject: [PATCH 1/2] chore(deps): update xunit-dotnet monorepo to v2.5.1 (#369) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .../DisCatSharp.Configuration.Tests.csproj | 4 ++-- .../DisCatSharp.EventHandlers.Tests.csproj | 4 ++-- DisCatSharp.Hosting.Tests/DisCatSharp.Hosting.Tests.csproj | 4 ++-- DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DisCatSharp.Configuration.Tests/DisCatSharp.Configuration.Tests.csproj b/DisCatSharp.Configuration.Tests/DisCatSharp.Configuration.Tests.csproj index 1b4ffaa7d..aeadc29c6 100644 --- a/DisCatSharp.Configuration.Tests/DisCatSharp.Configuration.Tests.csproj +++ b/DisCatSharp.Configuration.Tests/DisCatSharp.Configuration.Tests.csproj @@ -19,8 +19,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/DisCatSharp.EventHandlers.Tests/DisCatSharp.EventHandlers.Tests.csproj b/DisCatSharp.EventHandlers.Tests/DisCatSharp.EventHandlers.Tests.csproj index 93e6557d7..e0254c18d 100644 --- a/DisCatSharp.EventHandlers.Tests/DisCatSharp.EventHandlers.Tests.csproj +++ b/DisCatSharp.EventHandlers.Tests/DisCatSharp.EventHandlers.Tests.csproj @@ -10,8 +10,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/DisCatSharp.Hosting.Tests/DisCatSharp.Hosting.Tests.csproj b/DisCatSharp.Hosting.Tests/DisCatSharp.Hosting.Tests.csproj index 127b510b1..e0200ac36 100644 --- a/DisCatSharp.Hosting.Tests/DisCatSharp.Hosting.Tests.csproj +++ b/DisCatSharp.Hosting.Tests/DisCatSharp.Hosting.Tests.csproj @@ -19,8 +19,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj b/DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj index b60376399..d1e58f79f 100644 --- a/DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj +++ b/DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj @@ -18,8 +18,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all From f60dc779396cb8b40837c13732947573525b1fb1 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Mon, 18 Sep 2023 10:32:13 +0200 Subject: [PATCH 2/2] fix: Reworked application command equality check & registration --- .../ApplicationCommandsExtension.cs | 2 +- .../ApplicationCommandEqualityChecks.cs | 356 +++++++----------- .../Workers/RegistrationWorker.cs | 8 +- DisCatSharp/Net/Rest/DiscordApiClient.cs | 9 +- 4 files changed, 140 insertions(+), 235 deletions(-) diff --git a/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs b/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs index db07a1c14..e27527b1c 100644 --- a/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs +++ b/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs @@ -756,7 +756,7 @@ private async Task RegisterCommands(List { if (updateList != null && updateList.Any()) { - var regCommands = await RegistrationWorker.RegisterGuildCommandsAsync(this.Client, guildId.Value, updateList).ConfigureAwait(false); + var regCommands = await RegistrationWorker.RegisterGuildCommandsAsync(this.Client, guildId.Value, updateList).ConfigureAwait(false); var actualCommands = regCommands.Distinct().ToList(); commands.AddRange(actualCommands); GuildCommandsInternal.Add(guildId.Value, actualCommands); diff --git a/DisCatSharp.ApplicationCommands/Checks/ApplicationCommandEqualityChecks.cs b/DisCatSharp.ApplicationCommands/Checks/ApplicationCommandEqualityChecks.cs index 4a54634d9..60cbebf8d 100644 --- a/DisCatSharp.ApplicationCommands/Checks/ApplicationCommandEqualityChecks.cs +++ b/DisCatSharp.ApplicationCommands/Checks/ApplicationCommandEqualityChecks.cs @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System; using System.Collections.Generic; using System.Linq; @@ -41,7 +42,8 @@ internal static class ApplicationCommandEqualityChecks /// Command to check against. /// The discord client. /// Whether the equal check is performed for a guild command. - internal static bool IsEqualTo(this DiscordApplicationCommand ac1, DiscordApplicationCommand targetApplicationCommand, DiscordClient client, bool isGuild) + internal static bool IsEqualTo(this DiscordApplicationCommand ac1, + DiscordApplicationCommand targetApplicationCommand, DiscordClient client, bool isGuild) { if (targetApplicationCommand is null || ac1 is null) return false; @@ -54,7 +56,8 @@ internal static bool IsEqualTo(this DiscordApplicationCommand ac1, DiscordApplic ac1.IsNsfw, ac1.AllowedContexts, ac1.IntegrationTypes ); - if (sourceApplicationCommand.DefaultMemberPermissions == Permissions.None && targetApplicationCommand.DefaultMemberPermissions == null) + if (sourceApplicationCommand.DefaultMemberPermissions == Permissions.None && + targetApplicationCommand.DefaultMemberPermissions == null) sourceApplicationCommand.DefaultMemberPermissions = null; if (isGuild) @@ -62,10 +65,19 @@ internal static bool IsEqualTo(this DiscordApplicationCommand ac1, DiscordApplic sourceApplicationCommand.DmPermission = null; targetApplicationCommand.DmPermission = null; } + else + { + sourceApplicationCommand.IntegrationTypes ??= new() { ApplicationCommandIntegrationTypes.InstalledToGuild }; + targetApplicationCommand.IntegrationTypes ??= new() { ApplicationCommandIntegrationTypes.InstalledToGuild }; + } - client.Logger.Log(ApplicationCommandsExtension.ApplicationCommandsLogLevel, "[AC Change Check] Command {name}\n\n[{jsonOne},{jsontwo}]\n\n", ac1.Name, JsonConvert.SerializeObject(sourceApplicationCommand), JsonConvert.SerializeObject(targetApplicationCommand)); + client.Logger.Log(ApplicationCommandsExtension.ApplicationCommandsLogLevel, + "[AC Change Check] Command {name}\n\n[{jsonOne},{jsontwo}]\n\n", ac1.Name, + JsonConvert.SerializeObject(sourceApplicationCommand), + JsonConvert.SerializeObject(targetApplicationCommand)); - return ac1.Type == targetApplicationCommand.Type && sourceApplicationCommand.SoftEqual(targetApplicationCommand, ac1.Type, ApplicationCommandsExtension.Configuration?.EnableLocalization ?? false, isGuild); + return ac1.Type == targetApplicationCommand.Type && sourceApplicationCommand.SoftEqual(targetApplicationCommand, + ac1.Type, ApplicationCommandsExtension.Configuration?.EnableLocalization ?? false, isGuild); } /// @@ -77,7 +89,8 @@ internal static bool IsEqualTo(this DiscordApplicationCommand ac1, DiscordApplic /// The application command type. /// Whether localization is enabled. /// Whether the equal check is performed for a guild command. - internal static bool SoftEqual(this DiscordApplicationCommand source, DiscordApplicationCommand target, ApplicationCommandType type, bool localizationEnabled = false, bool guild = false) + internal static bool SoftEqual(this DiscordApplicationCommand source, DiscordApplicationCommand target, + ApplicationCommandType type, bool localizationEnabled = false, bool guild = false) { bool? sDmPerm = source.DmPermission ?? true; bool? tDmPerm = target.DmPermission ?? true; @@ -87,19 +100,21 @@ internal static bool SoftEqual(this DiscordApplicationCommand source, DiscordApp { ApplicationCommandType.ChatInput => DeepEqual(source, target, true, sDmPerm, tDmPerm), _ => source.Name == target.Name - && source.Type == target.Type && source.NameLocalizations == target.NameLocalizations - && source.DefaultMemberPermissions == target.DefaultMemberPermissions - && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw - && source.AllowedContexts == target.AllowedContexts && source.IntegrationTypes == target.IntegrationTypes + && source.Type == target.Type && source.NameLocalizations == target.NameLocalizations + && source.DefaultMemberPermissions == target.DefaultMemberPermissions + && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw + && source.AllowedContexts.NullableSequenceEqual(target.AllowedContexts) && + source.IntegrationTypes.NullableSequenceEqual(target.IntegrationTypes) } : type switch { ApplicationCommandType.ChatInput => DeepEqual(source, target, false, sDmPerm, tDmPerm), _ => source.Name == target.Name - && source.Type == target.Type - && source.DefaultMemberPermissions == target.DefaultMemberPermissions - && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw - && source.AllowedContexts == target.AllowedContexts && source.IntegrationTypes == target.IntegrationTypes + && source.Type == target.Type + && source.DefaultMemberPermissions == target.DefaultMemberPermissions + && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw + && source.AllowedContexts.NullableSequenceEqual(target.AllowedContexts) && + source.IntegrationTypes.NullableSequenceEqual(target.IntegrationTypes) }; sDmPerm = null; @@ -109,22 +124,43 @@ internal static bool SoftEqual(this DiscordApplicationCommand source, DiscordApp { ApplicationCommandType.ChatInput => DeepEqual(source, target, true, sDmPerm, tDmPerm), _ => source.Name == target.Name - && source.Type == target.Type && source.NameLocalizations == target.NameLocalizations - && source.DefaultMemberPermissions == target.DefaultMemberPermissions - && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw - && source.AllowedContexts == target.AllowedContexts && source.IntegrationTypes == target.IntegrationTypes + && source.Type == target.Type && source.NameLocalizations == target.NameLocalizations + && source.DefaultMemberPermissions == target.DefaultMemberPermissions + && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw + && source.AllowedContexts.NullableSequenceEqual(target.AllowedContexts) && + source.IntegrationTypes.NullableSequenceEqual(target.IntegrationTypes) } : type switch { ApplicationCommandType.ChatInput => DeepEqual(source, target, false, sDmPerm, tDmPerm), _ => source.Name == target.Name - && source.Type == target.Type - && source.DefaultMemberPermissions == target.DefaultMemberPermissions - && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw - && source.AllowedContexts == target.AllowedContexts && source.IntegrationTypes == target.IntegrationTypes + && source.Type == target.Type + && source.DefaultMemberPermissions == target.DefaultMemberPermissions + && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw + && source.AllowedContexts.NullableSequenceEqual(target.AllowedContexts) && + source.IntegrationTypes.NullableSequenceEqual(target.IntegrationTypes) }; } + /// + /// Performs a SequenceEqual on a list if both and is not null. + /// + /// The containing type within the list. + /// The source list. + /// The target list. + /// Whether both nullable lists are equal. + internal static bool NullableSequenceEqual(this List? source, List? target) + { + if (source is not null && target is not null) + return source.OrderBy(x => x).SequenceEqual(target.OrderBy(x => x)); + + if ((source is not null && target is null) || + (source is null && target is not null)) + return false; + + return true; + } + /// /// Checks deeply whether two s are the same. /// Excluding id, application id and version here. @@ -134,220 +170,96 @@ internal static bool SoftEqual(this DiscordApplicationCommand source, DiscordApp /// Whether localization is enabled. /// The source dm permission. /// The target dm permission. - internal static bool DeepEqual(DiscordApplicationCommand source, DiscordApplicationCommand target, bool localizationEnabled = false, bool? sDmPerm = null, bool? tDmPerm = null) + internal static bool DeepEqual(DiscordApplicationCommand source, DiscordApplicationCommand target, + bool localizationEnabled = false, bool? sDmPerm = null, bool? tDmPerm = null) { - var rootCheck = true; - rootCheck = source.Name == target.Name && source.Description == target.Description && source.Type == target.Type && source.DefaultMemberPermissions == target.DefaultMemberPermissions && sDmPerm == tDmPerm && source.IsNsfw == target.IsNsfw && source.AllowedContexts == target.AllowedContexts && source.IntegrationTypes == target.IntegrationTypes; + var name = source.Name; + var rootCheck = source.Name == target.Name && + source.Description == target.Description && + source.Type == target.Type && + source.DefaultMemberPermissions == target.DefaultMemberPermissions && + sDmPerm == tDmPerm && + source.IsNsfw == target.IsNsfw + && source.AllowedContexts.NullableSequenceEqual(target.AllowedContexts) && + source.IntegrationTypes.NullableSequenceEqual(target.IntegrationTypes); if (localizationEnabled) - rootCheck = rootCheck && source.NameLocalizations == target.NameLocalizations && source.DescriptionLocalizations == target.DescriptionLocalizations; + rootCheck = rootCheck && + source.NameLocalizations.Localizations.SequenceEqual(target.NameLocalizations.Localizations) && + source.DescriptionLocalizations.Localizations.SequenceEqual(target.DescriptionLocalizations + .Localizations); - if (source.Options == null && target.Options == null) - return rootCheck; + // Compare the Options using recursion + var optionsEqual = DeepEqualOptions(source.Options, target.Options, localizationEnabled); - if ((source.Options != null && target.Options == null) || (source.Options == null && target.Options != null)) - return false; - - if (source.Options.Any(o => o.Type is ApplicationCommandOptionType.SubCommandGroup or ApplicationCommandOptionType.SubCommand) && target.Options.Any(o => o.Type is ApplicationCommandOptionType.SubCommandGroup or ApplicationCommandOptionType.SubCommand)) - { - var eqCheck1 = true; - var eqCheck2 = true; - if (source.Options.Any(o => o.Type == ApplicationCommandOptionType.SubCommandGroup) && - target.Options.Any(o => o.Type == ApplicationCommandOptionType.SubCommandGroup)) - { - List minimalSourceOptions = new(); - List minimalTargetOptions = new(); - - foreach (var option in - source.Options.Where(x => x.Type == ApplicationCommandOptionType.SubCommandGroup)) - { - List minimalSubSourceOptions = new(); - if (option.Options != null) - { - foreach (var subOption in option.Options) - { - List minimalSubSubSourceOptions = null; - - if (subOption.Options != null) - { - minimalSubSubSourceOptions = new(); - - foreach (var subSubOption in subOption.Options) - minimalSubSubSourceOptions.Add(new DiscordApplicationCommandOption( - subSubOption.Name, subSubOption.Description, subSubOption.Type, - subSubOption.Required, - subSubOption.Choices, null, subSubOption.ChannelTypes?.OrderBy(x => x), - subSubOption.AutoComplete, - subSubOption.MinimumValue, subSubOption.MaximumValue, - localizationEnabled ? subSubOption.NameLocalizations : null, - localizationEnabled ? subSubOption.DescriptionLocalizations : null, - subSubOption.MinimumLength, subSubOption.MaximumLength - )); - - minimalSubSourceOptions.Add(new DiscordApplicationCommandOption( - subOption.Name, subOption.Description, subOption.Type, - options: minimalSubSubSourceOptions, - nameLocalizations: localizationEnabled ? subOption.NameLocalizations : null, - descriptionLocalizations: localizationEnabled - ? subOption.DescriptionLocalizations - : null - )); - } - } - - } - - minimalSourceOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, - options: minimalSubSourceOptions, - nameLocalizations: localizationEnabled ? option.NameLocalizations : null, - descriptionLocalizations: localizationEnabled ? option.DescriptionLocalizations : null - )); - } + return rootCheck && optionsEqual; + } - foreach (var option in - target.Options.Where(x => x.Type == ApplicationCommandOptionType.SubCommandGroup)) - { - List minimalSubTargetOptions = new(); - - foreach (var subOption in option.Options) - { - List minimalSubSubTargetOptions = null; - - if (subOption.Options != null && subOption.Options.Any()) - { - minimalSubSubTargetOptions = new(); - - foreach (var subSubOption in subOption.Options) - minimalSubSubTargetOptions.Add(new DiscordApplicationCommandOption( - subSubOption.Name, subSubOption.Description, subSubOption.Type, - subSubOption.Required, - subSubOption.Choices, null, subSubOption.ChannelTypes?.OrderBy(x => x), subSubOption.AutoComplete, - subSubOption.MinimumValue, subSubOption.MaximumValue, - localizationEnabled ? subSubOption.NameLocalizations : null, - localizationEnabled ? subSubOption.DescriptionLocalizations : null, - subSubOption.MinimumLength, subSubOption.MaximumLength - )); - - minimalSubTargetOptions.Add(new DiscordApplicationCommandOption( - subOption.Name, subOption.Description, subOption.Type, - options: minimalSubSubTargetOptions, - nameLocalizations: localizationEnabled ? subOption.NameLocalizations : null, - descriptionLocalizations: localizationEnabled - ? subOption.DescriptionLocalizations - : null - )); - } - } - - minimalTargetOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, - options: minimalSubTargetOptions, - nameLocalizations: localizationEnabled ? option.NameLocalizations : null, - descriptionLocalizations: localizationEnabled ? option.DescriptionLocalizations : null - )); - } + /// + /// Checks deeply whether s are the same. + /// + /// Source options. + /// Options to check against. + /// Whether localization is enabled. + private static bool DeepEqualOptions(IReadOnlyList? sourceOptions, + IReadOnlyList? targetOptions, bool localizationEnabled) + { + if (sourceOptions == null && targetOptions == null) + return true; - var sOpt = JsonConvert.SerializeObject(minimalSourceOptions, Formatting.None); - var tOpt = JsonConvert.SerializeObject(minimalTargetOptions, Formatting.None); + if ((sourceOptions != null && targetOptions == null) || (sourceOptions == null && targetOptions != null)) + return false; - eqCheck1 = rootCheck && sOpt == tOpt; - } + if (sourceOptions!.Count != targetOptions!.Count) + return false; - if (source.Options.Any(o => o.Type == ApplicationCommandOptionType.SubCommand) && - target.Options.Any(o => o.Type == ApplicationCommandOptionType.SubCommand)) + for (var i = 0; i < sourceOptions.Count; i++) + { + var sourceOption = sourceOptions[i]; + var targetOption = targetOptions[i]; + + var optionCheck = sourceOption.Name == targetOption.Name && + sourceOption.Description == targetOption.Description && + sourceOption.Type == targetOption.Type && + sourceOption.Required == targetOption.Required && + sourceOption.AutoComplete == targetOption.AutoComplete && + sourceOption.MinimumValue == targetOption.MinimumValue && + sourceOption.MaximumValue == targetOption.MaximumValue && + sourceOption.MinimumLength == targetOption.MinimumLength && + sourceOption.MaximumLength == targetOption.MaximumLength; + + if (localizationEnabled) + optionCheck = optionCheck && + sourceOption.NameLocalizations.Localizations.SequenceEqual(targetOption.NameLocalizations + .Localizations) && + sourceOption.DescriptionLocalizations.Localizations.SequenceEqual(targetOption + .DescriptionLocalizations.Localizations); + + if ((sourceOption.Choices is null && targetOption.Choices is not null) || + (sourceOption.Choices is not null && targetOption.Choices is null)) + return false; + + if (sourceOption.Choices is not null && targetOption.Choices is not null) { - List minimalSourceOptions = new(); - List minimalTargetOptions = new(); - - foreach (var option in source.Options.Where(x => x.Type == ApplicationCommandOptionType.SubCommand)) - { - List minimalSubSourceOptions = null; - - if (option.Options != null) - { - minimalSubSourceOptions = new(); - - foreach (var subOption in option.Options) - minimalSubSourceOptions.Add(new DiscordApplicationCommandOption( - subOption.Name, subOption.Description, subOption.Type, subOption.Required, - subOption.Choices, null, subOption.ChannelTypes?.OrderBy(x => x), subOption.AutoComplete, - subOption.MinimumValue, subOption.MaximumValue, - localizationEnabled ? subOption.NameLocalizations : null, - localizationEnabled ? subOption.DescriptionLocalizations : null, - subOption.MinimumLength, subOption.MaximumLength - )); - } - - minimalSourceOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, - options: minimalSubSourceOptions, - nameLocalizations: localizationEnabled ? option.NameLocalizations : null, - descriptionLocalizations: localizationEnabled ? option.DescriptionLocalizations : null - )); - } - - foreach (var option in target.Options.Where(x => x.Type == ApplicationCommandOptionType.SubCommand)) - { - List minimalSubTargetOptions = null; - - if (option.Options != null && option.Options.Any()) - { - minimalSubTargetOptions = new(); - - foreach (var subOption in option.Options) - minimalSubTargetOptions.Add(new DiscordApplicationCommandOption( - subOption.Name, subOption.Description, subOption.Type, subOption.Required, - subOption.Choices, null, subOption.ChannelTypes?.OrderBy(x => x), subOption.AutoComplete, - subOption.MinimumValue, subOption.MaximumValue, - localizationEnabled ? subOption.NameLocalizations : null, - localizationEnabled ? subOption.DescriptionLocalizations : null, - subOption.MinimumLength, subOption.MaximumLength - )); - } - - minimalTargetOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, - options: minimalSubTargetOptions, - nameLocalizations: localizationEnabled ? option.NameLocalizations : null, - descriptionLocalizations: localizationEnabled ? option.DescriptionLocalizations : null - )); - } + var j1 = JsonConvert.SerializeObject(sourceOption.Choices.OrderBy(x => x.Name), Formatting.None); + var j2 = JsonConvert.SerializeObject(targetOption.Choices.OrderBy(x => x.Name), Formatting.None); + if (j1 != j2) + return false; + } - var sOpt = JsonConvert.SerializeObject(minimalSourceOptions, Formatting.None); - var tOpt = JsonConvert.SerializeObject(minimalTargetOptions, Formatting.None); + if ((sourceOption.ChannelTypes is null && targetOption.ChannelTypes is not null) || + (sourceOption.ChannelTypes is not null && targetOption.ChannelTypes is null) || + (sourceOption.ChannelTypes is not null && targetOption.ChannelTypes is not null && + !sourceOption.ChannelTypes.OrderBy(x => x).All(targetOption.ChannelTypes.OrderBy(x => x).Contains))) + return false; - eqCheck2 = rootCheck && sOpt == tOpt; - } + if (!DeepEqualOptions(sourceOption.Options, targetOption.Options, localizationEnabled)) + return false; - return eqCheck1 && eqCheck2; - } - else - { - List minimalSourceOptions = new(); - List minimalTargetOptions = new(); - - foreach (var option in source.Options) - minimalSourceOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, option.Required, - option.Choices, null, option.ChannelTypes?.OrderBy(x => x), option.AutoComplete, option.MinimumValue, option.MaximumValue, - localizationEnabled ? option.NameLocalizations : null, - localizationEnabled ? option.DescriptionLocalizations : null, - option.MinimumLength, option.MaximumLength - )); - - foreach (var option in target.Options) - minimalTargetOptions.Add(new DiscordApplicationCommandOption( - option.Name, option.Description, option.Type, option.Required, - option.Choices, null, option.ChannelTypes?.OrderBy(x => x), option.AutoComplete, option.MinimumValue, option.MaximumValue, - localizationEnabled ? option.NameLocalizations : null, - localizationEnabled ? option.DescriptionLocalizations : null, - option.MinimumLength, option.MaximumLength - )); - var sOpt = JsonConvert.SerializeObject(minimalSourceOptions, Formatting.None); - var tOpt = JsonConvert.SerializeObject(minimalTargetOptions, Formatting.None); - - return rootCheck && sOpt == tOpt; + if (!optionCheck) + return false; } + + return true; } } diff --git a/DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs b/DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs index 23044b79a..eef888262 100644 --- a/DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs +++ b/DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs @@ -453,9 +453,7 @@ List unchangedCommands /// A list of command ids. private static List BuildGlobalDeleteList(DiscordClient client, List updateList = null) { - if (ApplicationCommandsExtension.GlobalDiscordCommands == null || !ApplicationCommandsExtension.GlobalDiscordCommands.Any() - || ApplicationCommandsExtension.GlobalDiscordCommands == null - ) + if (ApplicationCommandsExtension.GlobalDiscordCommands == null || !ApplicationCommandsExtension.GlobalDiscordCommands.Any()) return null; var discord = ApplicationCommandsExtension.GlobalDiscordCommands; @@ -512,9 +510,7 @@ private static ( List unchangedCommands ) BuildGlobalOverwriteList(DiscordClient client, List updateList) { - if (ApplicationCommandsExtension.GlobalDiscordCommands == null || !ApplicationCommandsExtension.GlobalDiscordCommands.Any() - || updateList == null || ApplicationCommandsExtension.GlobalDiscordCommands == null - ) + if (ApplicationCommandsExtension.GlobalDiscordCommands == null || !ApplicationCommandsExtension.GlobalDiscordCommands.Any() || updateList == null) return (null, null); var discord = ApplicationCommandsExtension.GlobalDiscordCommands; diff --git a/DisCatSharp/Net/Rest/DiscordApiClient.cs b/DisCatSharp/Net/Rest/DiscordApiClient.cs index 72503d0d7..0a4eed0a7 100644 --- a/DisCatSharp/Net/Rest/DiscordApiClient.cs +++ b/DisCatSharp/Net/Rest/DiscordApiClient.cs @@ -5428,8 +5428,7 @@ internal async Task> BulkOverwriteGuild DefaultMemberPermission = command.DefaultMemberPermissions, DmPermission = command.DmPermission, Nsfw = command.IsNsfw, - AllowedContexts = command.AllowedContexts, - IntegrationTypes = command.IntegrationTypes + AllowedContexts = command.AllowedContexts }); } @@ -5462,8 +5461,7 @@ internal async Task CreateGuildApplicationCommandAsyn DefaultMemberPermission = command.DefaultMemberPermissions, DmPermission = command.DmPermission, Nsfw = command.IsNsfw, - AllowedContexts = command.AllowedContexts, - IntegrationTypes = command.IntegrationTypes + AllowedContexts = command.AllowedContexts }; var route = $"{Endpoints.APPLICATIONS}/:application_id{Endpoints.GUILDS}/:guild_id{Endpoints.COMMANDS}"; @@ -5532,8 +5530,7 @@ internal async Task EditGuildApplicationCommandAsync( NameLocalizations = nameLocalization.Map(l => l.GetKeyValuePairs()).ValueOrDefault(), DescriptionLocalizations = descriptionLocalization.Map(l => l.GetKeyValuePairs()).ValueOrDefault(), Nsfw = isNsfw, - AllowedContexts = allowedContexts, - IntegrationTypes = integrationTypes + AllowedContexts = allowedContexts }; var route = $"{Endpoints.APPLICATIONS}/:application_id{Endpoints.GUILDS}/:guild_id{Endpoints.COMMANDS}/:command_id";