Files
Discord.Net/src/Discord.Net.Commands/Map/CommandMap.cs
FiniteReality 70d30efb94 Implement configurable command node separators
This fixes #304 over foxbot's PR for the same issue.
2016-12-09 10:31:57 +00:00

40 lines
1.1 KiB
C#

using System.Collections.Generic;
namespace Discord.Commands
{
internal class CommandMap
{
private readonly CommandMapNode _root;
private static readonly string[] _blankAliases = new[] { "" };
public CommandMap()
{
_root = new CommandMapNode("");
}
public void AddCommand(CommandInfo command, CommandService service)
{
foreach (string text in GetAliases(command))
_root.AddCommand(service, text, 0, command);
}
public void RemoveCommand(CommandInfo command, CommandService service)
{
foreach (string text in GetAliases(command))
_root.RemoveCommand(service, text, 0, command);
}
public IEnumerable<CommandInfo> GetCommands(string text, CommandService service)
{
return _root.GetCommands(service, text, 0);
}
private IReadOnlyList<string> GetAliases(CommandInfo command)
{
var aliases = command.Aliases;
if (aliases.Count == 0)
return _blankAliases;
return aliases;
}
}
}