Fix a bunch of issues with aliases
This commit is contained in:
@@ -118,7 +118,6 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
builder.Name = method.Name;
|
builder.Name = method.Name;
|
||||||
|
|
||||||
var setName = false;
|
|
||||||
foreach (var attribute in attributes)
|
foreach (var attribute in attributes)
|
||||||
{
|
{
|
||||||
// TODO: C#7 type switch
|
// TODO: C#7 type switch
|
||||||
@@ -127,12 +126,11 @@ namespace Discord.Commands
|
|||||||
var cmdAttr = attribute as CommandAttribute;
|
var cmdAttr = attribute as CommandAttribute;
|
||||||
builder.AddAliases(cmdAttr.Text);
|
builder.AddAliases(cmdAttr.Text);
|
||||||
builder.RunMode = cmdAttr.RunMode;
|
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)
|
else if (attribute is NameAttribute)
|
||||||
{
|
{
|
||||||
builder.Name = (attribute as NameAttribute).Text;
|
builder.Name = (attribute as NameAttribute).Text;
|
||||||
setName = true;
|
|
||||||
}
|
}
|
||||||
else if (attribute is PriorityAttribute)
|
else if (attribute is PriorityAttribute)
|
||||||
builder.Priority = (attribute as PriorityAttribute).Priority;
|
builder.Priority = (attribute as PriorityAttribute).Priority;
|
||||||
@@ -146,6 +144,9 @@ namespace Discord.Commands
|
|||||||
builder.AddPrecondition(attribute as PreconditionAttribute);
|
builder.AddPrecondition(attribute as PreconditionAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (builder.Name == null)
|
||||||
|
builder.Name = method.Name;
|
||||||
|
|
||||||
var parameters = method.GetParameters();
|
var parameters = method.GetParameters();
|
||||||
int pos = 0, count = parameters.Length;
|
int pos = 0, count = parameters.Length;
|
||||||
foreach (var paramInfo in parameters)
|
foreach (var paramInfo in parameters)
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ namespace Discord.Commands
|
|||||||
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
||||||
private readonly CommandMap _map;
|
private readonly CommandMap _map;
|
||||||
|
|
||||||
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value);
|
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x);
|
||||||
public IEnumerable<CommandInfo> Commands => _typedModuleDefs.SelectMany(x => x.Value.Commands);
|
public IEnumerable<CommandInfo> Commands => _moduleDefs.SelectMany(x => x.Commands);
|
||||||
|
|
||||||
public CommandService()
|
public CommandService()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
// both command and module provide aliases
|
// both command and module provide aliases
|
||||||
if (module.Aliases.Count > 0 && builder.Aliases.Count > 0)
|
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
|
// only module provides aliases
|
||||||
else if (module.Aliases.Count > 0)
|
else if (module.Aliases.Count > 0)
|
||||||
Aliases = module.Aliases.ToImmutableArray();
|
Aliases = module.Aliases.ToImmutableArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user