Cleaned up a few internal command constructor, fixed subgroups not maintaining category
This commit is contained in:
@@ -121,10 +121,11 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
public CommandService Service => _service;
|
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;
|
_service = service;
|
||||||
_prefix = prefix;
|
_prefix = prefix;
|
||||||
|
_category = category;
|
||||||
if (initialChecks != null)
|
if (initialChecks != null)
|
||||||
_checks = new List<IPermissionChecker>(initialChecks);
|
_checks = new List<IPermissionChecker>(initialChecks);
|
||||||
else
|
else
|
||||||
@@ -145,9 +146,9 @@ namespace Discord.Commands
|
|||||||
_checks.Add(new GenericPermissionChecker(checkFunc, errorMsg));
|
_checks.Add(new GenericPermissionChecker(checkFunc, errorMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config = null)
|
public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config)
|
||||||
{
|
{
|
||||||
config(new CommandGroupBuilder(_service, CommandBuilder.AppendPrefix(_prefix, cmd), _checks));
|
config(new CommandGroupBuilder(_service, CommandBuilder.AppendPrefix(_prefix, cmd), _category, _checks));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public CommandBuilder CreateCommand()
|
public CommandBuilder CreateCommand()
|
||||||
|
|||||||
@@ -20,16 +20,20 @@ namespace Discord.Commands
|
|||||||
public IEnumerable<Command> Commands => _commands;
|
public IEnumerable<Command> Commands => _commands;
|
||||||
public IEnumerable<CommandMap> SubGroups => _items.Values;
|
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;
|
_parent = parent;
|
||||||
_name = name;
|
_name = name;
|
||||||
_fullName = fullName;
|
_fullName = fullName;
|
||||||
_items = new Dictionary<string, CommandMap>();
|
|
||||||
_commands = new List<Command>();
|
|
||||||
_isVisible = false;
|
|
||||||
_hasNonAliases = false;
|
|
||||||
_hasSubGroups = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandMap GetItem(string text)
|
public CommandMap GetItem(string text)
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ namespace Discord.Commands
|
|||||||
Config = config;
|
Config = config;
|
||||||
|
|
||||||
_allCommands = new List<Command>();
|
_allCommands = new List<Command>();
|
||||||
_map = new CommandMap(null, "", "");
|
_map = new CommandMap();
|
||||||
_categories = new Dictionary<string, CommandMap>();
|
_categories = new Dictionary<string, CommandMap>();
|
||||||
Root = new CommandGroupBuilder(this, "", null);
|
Root = new CommandGroupBuilder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IService.Install(DiscordClient client)
|
void IService.Install(DiscordClient client)
|
||||||
@@ -309,7 +309,7 @@ namespace Discord.Commands
|
|||||||
string categoryName = command.Category ?? "";
|
string categoryName = command.Category ?? "";
|
||||||
if (!_categories.TryGetValue(categoryName, out category))
|
if (!_categories.TryGetValue(categoryName, out category))
|
||||||
{
|
{
|
||||||
category = new CommandMap(null, "", "");
|
category = new CommandMap();
|
||||||
_categories.Add(categoryName, category);
|
_categories.Add(categoryName, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user