Browse Source

Cleaned up a few internal command constructor, fixed subgroups not maintaining category

tags/docs-0.9
RogueException 9 years ago
parent
commit
f581434497
3 changed files with 18 additions and 13 deletions
  1. +5
    -4
      src/Discord.Net.Commands/CommandBuilder.cs
  2. +10
    -6
      src/Discord.Net.Commands/CommandMap.cs
  3. +3
    -3
      src/Discord.Net.Commands/CommandService.cs

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

@@ -121,10 +121,11 @@ namespace Discord.Commands

public CommandService Service => _service;

internal CommandGroupBuilder(CommandService service, string prefix, IEnumerable<IPermissionChecker> initialChecks = null)
internal CommandGroupBuilder(CommandService service, string prefix = "", string category = null, IEnumerable<IPermissionChecker> initialChecks = null)
{
_service = service;
_prefix = prefix;
_category = category;
if (initialChecks != null)
_checks = new List<IPermissionChecker>(initialChecks);
else
@@ -145,9 +146,9 @@ namespace Discord.Commands
_checks.Add(new GenericPermissionChecker(checkFunc, errorMsg));
}

public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config = null)
{
config(new CommandGroupBuilder(_service, CommandBuilder.AppendPrefix(_prefix, cmd), _checks));
public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config)
{
config(new CommandGroupBuilder(_service, CommandBuilder.AppendPrefix(_prefix, cmd), _category, _checks));
return this;
}
public CommandBuilder CreateCommand()


+ 10
- 6
src/Discord.Net.Commands/CommandMap.cs View File

@@ -20,16 +20,20 @@ namespace Discord.Commands
public IEnumerable<Command> Commands => _commands;
public IEnumerable<CommandMap> SubGroups => _items.Values;

public CommandMap(CommandMap parent, string name, string fullName)
public CommandMap()
{
_items = new Dictionary<string, CommandMap>();
_commands = new List<Command>();
_isVisible = false;
_hasNonAliases = false;
_hasSubGroups = false;
}
public CommandMap(CommandMap parent, string name, string fullName)
: this()
{
_parent = parent;
_name = name;
_fullName = fullName;
_items = new Dictionary<string, CommandMap>();
_commands = new List<Command>();
_isVisible = false;
_hasNonAliases = false;
_hasSubGroups = false;
}
public CommandMap GetItem(string text)


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

@@ -34,9 +34,9 @@ namespace Discord.Commands
Config = config;

_allCommands = new List<Command>();
_map = new CommandMap(null, "", "");
_map = new CommandMap();
_categories = new Dictionary<string, CommandMap>();
Root = new CommandGroupBuilder(this, "", null);
Root = new CommandGroupBuilder(this);
}

void IService.Install(DiscordClient client)
@@ -309,7 +309,7 @@ namespace Discord.Commands
string categoryName = command.Category ?? "";
if (!_categories.TryGetValue(categoryName, out category))
{
category = new CommandMap(null, "", "");
category = new CommandMap();
_categories.Add(categoryName, category);
}



Loading…
Cancel
Save