diff --git a/DeukBot4/MessageHandlers/CommandHandler/Command.cs b/DeukBot4/MessageHandlers/CommandHandler/Command.cs index 8a86539..a9ee90a 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/Command.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/Command.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System.Collections.Generic; +using System.Reflection; using System.Threading.Tasks; using DeukBot4.MessageHandlers.CommandHandler.RequestStructure; using DeukBot4.MessageHandlers.Permissions; @@ -41,6 +42,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler } public string Name { get; } + public List Alternatives { get; } = new List(); public PermissionLevel Permission { get; } public string ShortHelp { get; } public string LongHelp { get; } diff --git a/DeukBot4/MessageHandlers/CommandHandler/CommandContainerBase.cs b/DeukBot4/MessageHandlers/CommandHandler/CommandContainerBase.cs index 7ce08cd..55cdc7d 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/CommandContainerBase.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/CommandContainerBase.cs @@ -19,7 +19,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler { // grab all command attributes, cast them properly var commandAttributes = methodInfo.GetCustomAttributes(typeof(CommandAttribute), true) - .Select(x => x as CommandAttribute); + .Select(x => x as CommandAttribute).ToArray(); // get the help attribute if it exists CommandHelpAttribute helpAttribute = null; @@ -40,24 +40,28 @@ namespace DeukBot4.MessageHandlers.CommandHandler var matchParametersExactly = methodInfo.GetCustomAttributes(typeof(RequireParameterMatchAttribute), true).Any(); - - foreach (var commandAttribute in commandAttributes) + var firstCommand = commandAttributes.First(); + Command command; + if (helpAttribute == null) { - if (commandAttribute == null) - continue; - if (helpAttribute == null) - { - commands.Add(new Command(commandAttribute.Command, commandAttribute.Permission, parameters, - forbidPm, matchParametersExactly, methodInfo, this)); - } - else - { - commands.Add(new Command(commandAttribute.Command, commandAttribute.Permission, - helpAttribute.ShortHelp, helpAttribute.LongHelp, parameters, forbidPm, - matchParametersExactly, methodInfo, this)); - - } + command = (new Command(firstCommand.Command, firstCommand.Permission, parameters, + forbidPm, matchParametersExactly, methodInfo, this)); } + else + { + command = (new Command(firstCommand.Command, firstCommand.Permission, + helpAttribute.ShortHelp, helpAttribute.LongHelp, parameters, forbidPm, + matchParametersExactly, methodInfo, this)); + + } + for (var i = 1; i < commandAttributes.Length; i++) + { + var cmd = commandAttributes[i]; + if (cmd == null) + continue; + command.Alternatives.Add(cmd.Command); + } + commands.Add(command); } return commands.ToArray(); } diff --git a/DeukBot4/MessageHandlers/CommandHandler/CommandHandler.cs b/DeukBot4/MessageHandlers/CommandHandler/CommandHandler.cs index 2c4b897..fad6f03 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/CommandHandler.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/CommandHandler.cs @@ -29,6 +29,10 @@ namespace DeukBot4.MessageHandlers.CommandHandler foreach (var command in commands) { Commands.Add(command.Name.ToLowerInvariant(), command); + foreach (var commandAlternative in command.Alternatives) + { + Commands.Add(commandAlternative.ToLowerInvariant(), command); + } } Logger.Log( diff --git a/DeukBot4/MessageHandlers/CommandHandler/HelpCommandGenerator.cs b/DeukBot4/MessageHandlers/CommandHandler/HelpCommandGenerator.cs index e32042b..450c03a 100644 --- a/DeukBot4/MessageHandlers/CommandHandler/HelpCommandGenerator.cs +++ b/DeukBot4/MessageHandlers/CommandHandler/HelpCommandGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Text; using DeukBot4.MessageHandlers.Permissions; using Discord; @@ -17,6 +18,8 @@ namespace DeukBot4.MessageHandlers.CommandHandler continue; if (!command.Value.HasHelp) continue; + if (command.Value.Alternatives.Contains(command.Key)) + continue; if (!dic.TryGetValue(command.Value.CommandContainer.Name, out var entry)) { dic.Add(command.Value.CommandContainer.Name, new Dictionary()); @@ -25,6 +28,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler entry.Add(command.Value.Name, command.Value.ShortHelp); } var sb = new StringBuilder(); + Console.WriteLine(dic.Count); foreach (var entry in dic) { sb.Append($"**{entry.Key}**\n");