Fix a bunch of issues with aliases

This commit is contained in:
FiniteReality
2016-11-20 20:20:23 +00:00
parent fd5e237b41
commit 05fb81c617
3 changed files with 7 additions and 6 deletions

View File

@@ -118,7 +118,6 @@ namespace Discord.Commands
builder.Name = method.Name;
var setName = false;
foreach (var attribute in attributes)
{
// TODO: C#7 type switch
@@ -127,12 +126,11 @@ namespace Discord.Commands
var cmdAttr = attribute as CommandAttribute;
builder.AddAliases(cmdAttr.Text);
builder.RunMode = cmdAttr.RunMode;
builder.Name = setName ? builder.Name ?? cmdAttr.Text : cmdAttr.Text ?? builder.Name;
builder.Name = builder.Name ?? cmdAttr.Text;
}
else if (attribute is NameAttribute)
{
builder.Name = (attribute as NameAttribute).Text;
setName = true;
}
else if (attribute is PriorityAttribute)
builder.Priority = (attribute as PriorityAttribute).Priority;
@@ -146,6 +144,9 @@ namespace Discord.Commands
builder.AddPrecondition(attribute as PreconditionAttribute);
}
if (builder.Name == null)
builder.Name = method.Name;
var parameters = method.GetParameters();
int pos = 0, count = parameters.Length;
foreach (var paramInfo in parameters)

View File

@@ -19,8 +19,8 @@ namespace Discord.Commands
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
private readonly CommandMap _map;
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value);
public IEnumerable<CommandInfo> Commands => _typedModuleDefs.SelectMany(x => x.Value.Commands);
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x);
public IEnumerable<CommandInfo> Commands => _moduleDefs.SelectMany(x => x.Commands);
public CommandService()
{

View File

@@ -42,7 +42,7 @@ namespace Discord.Commands
// both command and module provide aliases
if (module.Aliases.Count > 0 && builder.Aliases.Count > 0)
Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => first + " " + second).ToImmutableArray();
Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => second != null ? first + " " + second : first).ToImmutableArray();
// only module provides aliases
else if (module.Aliases.Count > 0)
Aliases = module.Aliases.ToImmutableArray();