From d6d7a61d719bbfbacc71952e4d6cd58024a78e63 Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sun, 2 Jan 2022 16:34:15 +0300 Subject: [PATCH] init --- .../Info/Commands/CommandInfo.cs | 17 ++++++++++++++++- src/Discord.Net.Interactions/Info/ModuleInfo.cs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs index a72a28bbd..d609c535d 100644 --- a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs @@ -50,7 +50,7 @@ namespace Discord.Interactions public abstract bool SupportsWildCards { get; } /// - public bool IsTopLevelCommand => IgnoreGroupNames || !Module.IsTopLevelGroup; + public bool IsTopLevelCommand { get; } /// public RunMode RunMode { get; } @@ -72,6 +72,7 @@ namespace Discord.Interactions Name = builder.Name; MethodName = builder.MethodName; IgnoreGroupNames = builder.IgnoreGroupNames; + IsTopLevelCommand = IgnoreGroupNames || CheckTopLevel(Module); RunMode = builder.RunMode != RunMode.Default ? builder.RunMode : commandService._runMode; Attributes = builder.Attributes.ToImmutableArray(); Preconditions = builder.Preconditions.ToImmutableArray(); @@ -230,6 +231,20 @@ namespace Discord.Interactions } } + private static bool CheckTopLevel(ModuleInfo parent) + { + var currentParent = parent; + + while (currentParent != null) + { + if (currentParent.IsTopLevelGroup) + return false; + + currentParent = currentParent.Parent; + } + return true; + } + // ICommandInfo /// diff --git a/src/Discord.Net.Interactions/Info/ModuleInfo.cs b/src/Discord.Net.Interactions/Info/ModuleInfo.cs index 8bf367df8..4450b55e3 100644 --- a/src/Discord.Net.Interactions/Info/ModuleInfo.cs +++ b/src/Discord.Net.Interactions/Info/ModuleInfo.cs @@ -115,7 +115,7 @@ namespace Discord.Interactions SubModules = BuildSubModules(builder, commandService, services).ToImmutableArray(); Attributes = BuildAttributes(builder).ToImmutableArray(); Preconditions = BuildPreconditions(builder).ToImmutableArray(); - IsTopLevelGroup = CheckTopLevel(parent); + IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent); DontAutoRegister = builder.DontAutoRegister; GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);