Conflicts: src/Discord.Net.Commands/CommandService.cstags/1.0-rc
@@ -115,7 +115,7 @@ namespace Discord.Commands | |||||
private static void BuildCommand(CommandBuilder builder, TypeInfo typeInfo, MethodInfo method, CommandService service) | private static void BuildCommand(CommandBuilder builder, TypeInfo typeInfo, MethodInfo method, CommandService service) | ||||
{ | { | ||||
var attributes = method.GetCustomAttributes(); | var attributes = method.GetCustomAttributes(); | ||||
foreach (var attribute in attributes) | foreach (var attribute in attributes) | ||||
{ | { | ||||
// TODO: C#7 type switch | // TODO: C#7 type switch | ||||
@@ -140,6 +140,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) | ||||
@@ -21,8 +21,8 @@ namespace Discord.Commands | |||||
internal readonly RunMode _defaultRunMode; | internal readonly RunMode _defaultRunMode; | ||||
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value); | |||||
public IEnumerable<CommandInfo> Commands => _typedModuleDefs.SelectMany(x => x.Value.Commands); | |||||
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x); | |||||
public IEnumerable<CommandInfo> Commands => _moduleDefs.SelectMany(x => x.Commands); | |||||
public CommandService() : this(new CommandServiceConfig()) { } | public CommandService() : this(new CommandServiceConfig()) { } | ||||
public CommandService(CommandServiceConfig config) | public CommandService(CommandServiceConfig config) | ||||
@@ -39,11 +39,19 @@ namespace Discord.Commands | |||||
RunMode = (builder.RunMode == RunMode.Default ? service._defaultRunMode : builder.RunMode); | RunMode = (builder.RunMode == RunMode.Default ? service._defaultRunMode : builder.RunMode); | ||||
Priority = builder.Priority; | Priority = builder.Priority; | ||||
if (module.Aliases.Count != 0) | |||||
Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => first + " " + second).ToImmutableArray(); | |||||
else | |||||
// 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 + " " + second : first).ToImmutableArray(); | |||||
// 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(); | ||||
@@ -49,15 +49,21 @@ namespace Discord.Commands | |||||
while (builderStack.Count() > 0) | while (builderStack.Count() > 0) | ||||
{ | { | ||||
ModuleBuilder level = builderStack.Pop(); // get the topmost builder | |||||
ModuleBuilder level = builderStack.Pop(); //get the topmost builder | |||||
if (result == null) | if (result == null) | ||||
result = level.Aliases.ToList(); // create a shallow copy so we don't overwrite the builder unexpectedly | |||||
{ | |||||
if (level.Aliases.Count > 0) | |||||
result = level.Aliases.ToList(); //create a shallow copy so we don't overwrite the builder unexpectedly | |||||
} | |||||
else if (result.Count() > level.Aliases.Count) | else if (result.Count() > level.Aliases.Count) | ||||
result = result.Permutate(level.Aliases, (first, second) => first + " " + second); | result = result.Permutate(level.Aliases, (first, second) => first + " " + second); | ||||
else | else | ||||
result = level.Aliases.Permutate(result, (second, first) => first + " " + second); | result = level.Aliases.Permutate(result, (second, first) => first + " " + second); | ||||
} | } | ||||
if (result == null) //there were no aliases; default to an empty list | |||||
result = new List<string>(); | |||||
return result; | return result; | ||||
} | } | ||||