From 35d07edbbdb752b743c351a11bcf81ea7d152587 Mon Sep 17 00:00:00 2001 From: Googie2149 Date: Wed, 4 Nov 2015 20:34:14 -0500 Subject: [PATCH] Help command changes --- src/Discord.Net.Commands/CommandBuilder.cs | 4 +- src/Discord.Net.Commands/CommandService.cs | 89 ++++++++++++---------- 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/Discord.Net.Commands/CommandBuilder.cs b/src/Discord.Net.Commands/CommandBuilder.cs index 99a8ae97c..4523dbbc6 100644 --- a/src/Discord.Net.Commands/CommandBuilder.cs +++ b/src/Discord.Net.Commands/CommandBuilder.cs @@ -74,9 +74,9 @@ namespace Discord.Commands private void Build() { _command.SetParameters(_params.ToArray()); - foreach (var alias in _command.Aliases) + _service.AddCommand(_command); + foreach (var alias in _command.Aliases) _service.Map.AddCommand(alias, _command); - _service.AddCommand(_command); } internal static string AppendPrefix(string prefix, string cmd) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index efc84d7b2..ba51d7479 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -116,62 +116,71 @@ namespace Discord.Commands }; } - public Task ShowHelp(User user, Channel channel) - { - int permissions = Config.PermissionResolver(user); - - StringBuilder output = new StringBuilder(); - output.AppendLine("These are the commands you can use:"); - output.Append(string.Join(", ", _commands - .Where(x => permissions >= x.MinPermissions && !x.IsHidden) - .Select(x => '`' + x.Text + '`'))); - - var chars = Config.CommandChars; - if (chars.Length > 0) - { - if (chars.Length == 1) - output.AppendLine($"\nYou can use `{chars[0]}` to call a command."); - else - output.AppendLine($"\nYou can use `{string.Join(" ", chars.Take(chars.Length - 1))}` or `{chars.Last()}` to call a command."); - } + public Task ShowHelp(User user, Channel channel) + { + int permissions = Config.PermissionResolver(user); - output.AppendLine("`help ` can tell you more about how to use a command."); + StringBuilder output = new StringBuilder(); + output.AppendLine("These are the commands you can use:"); + + output.Append(string.Join(", ", _map.SubCommands.Distinct() + .Where(x => permissions >= x.MinPermissions && !x.IsHidden) + .Select(x => '`' + x.Text + '`' + + (x.Aliases.Count() > 0 ? ", `" + string.Join("`, `", x.Aliases) + '`' : "")))); + + var chars = Config.CommandChars; + if (chars.Length > 0) + { + if (chars.Length == 1) + output.AppendLine($"\nYou can use `{chars[0]}` to call a command."); + else + output.AppendLine($"\nYou can use `{string.Join(" ", chars.Take(chars.Length - 1))}` or `{chars.Last()}` to call a command."); + } + + output.AppendLine("`help` `` can tell you more about how to use a command."); + + return _client.SendMessage(channel, output.ToString()); + } - return _client.SendMessage(channel, output.ToString()); - } - public Task ShowHelp(Command command, User user, Channel channel) { StringBuilder output = new StringBuilder(); - output.Append($"`{command.Text}`"); - if (command.MinArgs != null && command.MaxArgs != null) + foreach (string s in command.Parameters.Where(x => x.Type == ParameterType.Required) + .Select(x => x.Name)) + output.Append($" <`{s}`>"); + foreach (string s in command.Parameters.Where(x => x.Type == ParameterType.Optional) + .Select(x => x.Name)) + output.Append($" [`{s}`]"); + + if (command.Parameters.LastOrDefault(x => x.Type == ParameterType.Multiple) != null) + output.Append(" [`...`]"); + + if (command.Parameters.LastOrDefault(x => x.Type == ParameterType.Unparsed) != null) + output.Append(" [`--`]"); + + output.AppendLine($": {command.Description ?? "No description set for this command."}"); + + var sub = _map.GetMap(command.Text).SubCommands; + if (sub.Count() > 0) { - if (command.MinArgs == command.MaxArgs) - { - if (command.MaxArgs != 0) - output.Append($" {command.MinArgs.ToString()} Args"); - } - else - output.Append($" {command.MinArgs.ToString()} - {command.MaxArgs.ToString()} Args"); + int permissions = Config.PermissionResolver(user); + output.AppendLine("Sub Commands: `" + string.Join("`, `", sub.Where(x => permissions >= x.MinPermissions && !x.IsHidden) + .Select(x => x.Text.Substring(command.Text.Length + 1))) + '`'); } - else if (command.MinArgs != null && command.MaxArgs == null) - output.Append($" ≥{command.MinArgs.ToString()} Args"); - else if (command.MinArgs == null && command.MaxArgs != null) - output.Append($" ≤{command.MaxArgs.ToString()} Args"); - output.Append($": {command.Description ?? "No description set for this command."}"); + if (command.Aliases.Count() > 0) + output.Append($"Aliases: `" + string.Join("`, `", command.Aliases) + '`'); - return _client.SendMessage(channel, output.ToString()); - } + return _client.SendMessage(channel, output.ToString()); + } - public void CreateCommandGroup(string cmd, Action config = null) + public void CreateCommandGroup(string cmd, Action config = null) => config(new CommandGroupBuilder(this, cmd, 0)); public CommandBuilder CreateCommand(string cmd) { var command = new Command(cmd); - _commands.Add(command); return new CommandBuilder(this, command, ""); }