Added CommandMap.GetMap overloads
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
@@ -9,6 +10,9 @@ namespace Discord.Commands
|
|||||||
private Command _command;
|
private Command _command;
|
||||||
private readonly Dictionary<string, CommandMap> _subCommands;
|
private readonly Dictionary<string, CommandMap> _subCommands;
|
||||||
|
|
||||||
|
public Command Command => _command;
|
||||||
|
public IEnumerable<Command> SubCommands => _subCommands.Select(x => x.Value.Command).Where(x => x != null);
|
||||||
|
|
||||||
public CommandMap(CommandMap parent)
|
public CommandMap(CommandMap parent)
|
||||||
{
|
{
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
@@ -17,11 +21,18 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
public CommandMap GetMap(string text)
|
public CommandMap GetMap(string text)
|
||||||
{
|
{
|
||||||
CommandMap map;
|
return GetMap(0, text.Split(' '));
|
||||||
if (_subCommands.TryGetValue(text, out map))
|
}
|
||||||
return map;
|
public CommandMap GetMap(int index, string[] parts)
|
||||||
else
|
{
|
||||||
return null;
|
if (index != parts.Length)
|
||||||
|
{
|
||||||
|
string nextPart = parts[index];
|
||||||
|
CommandMap nextGroup;
|
||||||
|
if (_subCommands.TryGetValue(nextPart, out nextGroup))
|
||||||
|
return nextGroup.GetMap(index + 1, parts);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command GetCommand()
|
public Command GetCommand()
|
||||||
|
|||||||
Reference in New Issue
Block a user