Fix commands from being created with invalid aliases
This commit is contained in:
@@ -116,6 +116,9 @@ namespace Discord.Commands
|
||||
{
|
||||
var attributes = method.GetCustomAttributes();
|
||||
|
||||
builder.Name = method.Name;
|
||||
|
||||
var setName = false;
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
// TODO: C#7 type switch
|
||||
@@ -124,10 +127,13 @@ namespace Discord.Commands
|
||||
var cmdAttr = attribute as CommandAttribute;
|
||||
builder.AddAliases(cmdAttr.Text);
|
||||
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)
|
||||
{
|
||||
builder.Name = (attribute as NameAttribute).Text;
|
||||
setName = true;
|
||||
}
|
||||
else if (attribute is PriorityAttribute)
|
||||
builder.Priority = (attribute as PriorityAttribute).Priority;
|
||||
else if (attribute is SummaryAttribute)
|
||||
|
||||
@@ -39,11 +39,19 @@ namespace Discord.Commands
|
||||
|
||||
RunMode = builder.RunMode;
|
||||
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();
|
||||
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();
|
||||
// neither provide aliases
|
||||
else
|
||||
throw new InvalidOperationException("Cannot build a command without any aliases");
|
||||
|
||||
Preconditions = builder.Preconditions.ToImmutableArray();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user