Fixes an issue foxbot found in discordpull/423/head
| @@ -41,7 +41,9 @@ namespace Discord.Commands.Builders | |||||
| Discord.Preconditions.NotNull(callback, nameof(callback)); | Discord.Preconditions.NotNull(callback, nameof(callback)); | ||||
| Callback = callback; | Callback = callback; | ||||
| _aliases.Add(primaryAlias); | |||||
| if (!string.IsNullOrWhiteSpace(primaryAlias)) | |||||
| _aliases.Add(primaryAlias); | |||||
| } | } | ||||
| public CommandBuilder WithName(string name) | public CommandBuilder WithName(string name) | ||||
| @@ -39,7 +39,8 @@ namespace Discord.Commands.Builders | |||||
| { | { | ||||
| Discord.Preconditions.NotNull(primaryAlias, nameof(primaryAlias)); | Discord.Preconditions.NotNull(primaryAlias, nameof(primaryAlias)); | ||||
| _aliases = new List<string> { primaryAlias }; | |||||
| if (!string.IsNullOrWhiteSpace(primaryAlias)) | |||||
| _aliases.Add(primaryAlias); | |||||
| } | } | ||||
| public ModuleBuilder WithName(string name) | public ModuleBuilder WithName(string name) | ||||
| @@ -44,13 +44,13 @@ 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) => second != null ? first + " " + second : first).Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).ToImmutableArray(); | |||||
| Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => !string.IsNullOrWhiteSpace(second) ? first + " " + second : first).Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).Distinct().ToImmutableArray(); | |||||
| // only module provides aliases | // only module provides aliases | ||||
| else if (module.Aliases.Count > 0) | else if (module.Aliases.Count > 0) | ||||
| Aliases = module.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).ToImmutableArray(); | |||||
| Aliases = module.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).Distinct().ToImmutableArray(); | |||||
| // only command provides aliases | // only command provides aliases | ||||
| else if (builder.Aliases.Count > 0) | else if (builder.Aliases.Count > 0) | ||||
| Aliases = builder.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).ToImmutableArray(); | |||||
| Aliases = builder.Aliases.Select(x => service._caseSensitive ? x : x.ToLowerInvariant()).Distinct().ToImmutableArray(); | |||||
| // neither provide aliases | // neither provide aliases | ||||
| else | else | ||||
| throw new InvalidOperationException("Cannot build a command without any aliases"); | throw new InvalidOperationException("Cannot build a command without any aliases"); | ||||
| @@ -15,7 +15,7 @@ namespace Discord.Commands | |||||
| public string Remarks { get; } | public string Remarks { get; } | ||||
| public IReadOnlyList<string> Aliases { get; } | public IReadOnlyList<string> Aliases { get; } | ||||
| public IEnumerable<CommandInfo> Commands { get; } | |||||
| public IReadOnlyList<CommandInfo> Commands { get; } | |||||
| public IReadOnlyList<PreconditionAttribute> Preconditions { get; } | public IReadOnlyList<PreconditionAttribute> Preconditions { get; } | ||||
| public IReadOnlyList<ModuleInfo> Submodules { get; } | public IReadOnlyList<ModuleInfo> Submodules { get; } | ||||
| public ModuleInfo Parent { get; } | public ModuleInfo Parent { get; } | ||||
| @@ -31,7 +31,7 @@ namespace Discord.Commands | |||||
| Parent = parent; | Parent = parent; | ||||
| Aliases = BuildAliases(builder).ToImmutableArray(); | 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(); | Preconditions = BuildPreconditions(builder).ToImmutableArray(); | ||||
| Submodules = BuildSubmodules(builder, service).ToImmutableArray(); | Submodules = BuildSubmodules(builder, service).ToImmutableArray(); | ||||
| @@ -68,7 +68,7 @@ namespace Discord.Commands | |||||
| if (result == null) //there were no aliases; default to an empty list | if (result == null) //there were no aliases; default to an empty list | ||||
| result = new List<string>(); | result = new List<string>(); | ||||
| return result; | |||||
| return result.Distinct(); | |||||
| } | } | ||||
| private List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service) | private List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service) | ||||