Cleaned up alias permutations, fixed empty aliases
This commit is contained in:
@@ -41,24 +41,19 @@ namespace Discord.Commands
|
||||
|
||||
RunMode = (builder.RunMode == RunMode.Default ? service._defaultRunMode : builder.RunMode);
|
||||
Priority = builder.Priority;
|
||||
|
||||
// both command and module provide aliases
|
||||
if (module.Aliases.Count > 0 && builder.Aliases.Count > 0)
|
||||
{
|
||||
Aliases = module.Aliases
|
||||
.Permutate(builder.Aliases, (first, second) => second != null ? first + service._separatorChar + second : first)
|
||||
.Select(x => service._caseSensitive ? x : x.ToLowerInvariant())
|
||||
.ToImmutableArray();
|
||||
}
|
||||
// only module provides aliases
|
||||
else if (module.Aliases.Count > 0)
|
||||
Aliases = module.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).ToImmutableArray();
|
||||
// only command provides aliases
|
||||
else if (builder.Aliases.Count > 0)
|
||||
Aliases = builder.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).ToImmutableArray();
|
||||
// neither provide aliases
|
||||
else
|
||||
throw new InvalidOperationException("Cannot build a command without any aliases");
|
||||
|
||||
Aliases = module.Aliases
|
||||
.Permutate(builder.Aliases, (first, second) =>
|
||||
{
|
||||
if (first == "")
|
||||
return second;
|
||||
else if (second == "")
|
||||
return first;
|
||||
else
|
||||
return first + service._separatorChar + second;
|
||||
})
|
||||
.Select(x => service._caseSensitive ? x : x.ToLowerInvariant())
|
||||
.ToImmutableArray();
|
||||
|
||||
Preconditions = builder.Preconditions.ToImmutableArray();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Discord.Commands
|
||||
public string Remarks { get; }
|
||||
|
||||
public IReadOnlyList<string> Aliases { get; }
|
||||
public IEnumerable<CommandInfo> Commands { get; }
|
||||
public IReadOnlyList<CommandInfo> Commands { get; }
|
||||
public IReadOnlyList<PreconditionAttribute> Preconditions { get; }
|
||||
public IReadOnlyList<ModuleInfo> Submodules { get; }
|
||||
public ModuleInfo Parent { get; }
|
||||
@@ -31,7 +31,7 @@ namespace Discord.Commands
|
||||
Parent = parent;
|
||||
|
||||
Aliases = BuildAliases(builder).ToImmutableArray();
|
||||
Commands = builder.Commands.Select(x => x.Build(this, service));
|
||||
Commands = builder.Commands.Select(x => x.Build(this, service)).ToImmutableArray();
|
||||
Preconditions = BuildPreconditions(builder).ToImmutableArray();
|
||||
|
||||
Submodules = BuildSubmodules(builder, service).ToImmutableArray();
|
||||
|
||||
Reference in New Issue
Block a user