Fix commands from being created with invalid aliases
This commit is contained in:
@@ -116,6 +116,9 @@ namespace Discord.Commands
|
|||||||
{
|
{
|
||||||
var attributes = method.GetCustomAttributes();
|
var attributes = method.GetCustomAttributes();
|
||||||
|
|
||||||
|
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
|
||||||
@@ -124,10 +127,13 @@ 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 = builder.Name ?? cmdAttr.Text;
|
builder.Name = setName ? builder.Name ?? cmdAttr.Text : cmdAttr.Text ?? builder.Name;
|
||||||
}
|
}
|
||||||
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;
|
||||||
else if (attribute is SummaryAttribute)
|
else if (attribute is SummaryAttribute)
|
||||||
|
|||||||
@@ -40,10 +40,18 @@ namespace Discord.Commands
|
|||||||
RunMode = builder.RunMode;
|
RunMode = builder.RunMode;
|
||||||
Priority = builder.Priority;
|
Priority = builder.Priority;
|
||||||
|
|
||||||
if (module.Aliases.Count != 0)
|
// 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) => first + " " + second).ToImmutableArray();
|
||||||
else
|
// only module provides aliases
|
||||||
|
else if (module.Aliases.Count > 0)
|
||||||
|
Aliases = module.Aliases.ToImmutableArray();
|
||||||
|
// only command provides aliases
|
||||||
|
else if (builder.Aliases.Count > 0)
|
||||||
Aliases = builder.Aliases.ToImmutableArray();
|
Aliases = builder.Aliases.ToImmutableArray();
|
||||||
|
// neither provide aliases
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException("Cannot build a command without any aliases");
|
||||||
|
|
||||||
Preconditions = builder.Preconditions.ToImmutableArray();
|
Preconditions = builder.Preconditions.ToImmutableArray();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user