Browse Source

Help command changes

tags/docs-0.9
Googie2149 9 years ago
parent
commit
35d07edbbd
2 changed files with 51 additions and 42 deletions
  1. +2
    -2
      src/Discord.Net.Commands/CommandBuilder.cs
  2. +49
    -40
      src/Discord.Net.Commands/CommandService.cs

+ 2
- 2
src/Discord.Net.Commands/CommandBuilder.cs View File

@@ -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)


+ 49
- 40
src/Discord.Net.Commands/CommandService.cs View File

@@ -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 <command>` 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` `<command>` 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<CommandGroupBuilder> config = null)
public void CreateCommandGroup(string cmd, Action<CommandGroupBuilder> 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, "");
}



Loading…
Cancel
Save