Implement Command Aliases

This implementation could probably be more efficient, but I
opted for clarity and simplicity where possible.
This commit is contained in:
FiniteReality
2016-08-26 22:23:37 +01:00
parent 99b6e8f07b
commit 95cf63243d
3 changed files with 56 additions and 13 deletions

View File

@@ -17,19 +17,21 @@ namespace Discord.Commands
public void AddCommand(Command command)
{
string text = command.Text;
int nextSpace = NextWhitespace(text);
string name;
if (nextSpace == -1)
name = command.Text;
else
name = command.Text.Substring(0, nextSpace);
lock (this)
foreach (string text in command.Aliases)
{
var nextNode = _nodes.GetOrAdd(name, x => new CommandMapNode(x));
nextNode.AddCommand(nextSpace == -1 ? "" : text, nextSpace + 1, command);
int nextSpace = NextWhitespace(text);
string name;
if (nextSpace == -1)
name = command.Text;
else
name = command.Text.Substring(0, nextSpace);
lock (this)
{
var nextNode = _nodes.GetOrAdd(name, x => new CommandMapNode(x));
nextNode.AddCommand(nextSpace == -1 ? "" : text, nextSpace + 1, command);
}
}
}
public void RemoveCommand(Command command)