Browse Source

Fix a bunch of issues with aliases

tags/1.0-rc
FiniteReality 8 years ago
parent
commit
05fb81c617
3 changed files with 7 additions and 6 deletions
  1. +4
    -3
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  2. +2
    -2
      src/Discord.Net.Commands/CommandService.cs
  3. +1
    -1
      src/Discord.Net.Commands/Info/CommandInfo.cs

+ 4
- 3
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -118,7 +118,6 @@ namespace Discord.Commands

builder.Name = method.Name;

var setName = false;
foreach (var attribute in attributes)
{
// TODO: C#7 type switch
@@ -127,12 +126,11 @@ namespace Discord.Commands
var cmdAttr = attribute as CommandAttribute;
builder.AddAliases(cmdAttr.Text);
builder.RunMode = cmdAttr.RunMode;
builder.Name = setName ? builder.Name ?? cmdAttr.Text : cmdAttr.Text ?? builder.Name;
builder.Name = builder.Name ?? cmdAttr.Text;
}
else if (attribute is NameAttribute)
{
builder.Name = (attribute as NameAttribute).Text;
setName = true;
}
else if (attribute is PriorityAttribute)
builder.Priority = (attribute as PriorityAttribute).Priority;
@@ -146,6 +144,9 @@ namespace Discord.Commands
builder.AddPrecondition(attribute as PreconditionAttribute);
}

if (builder.Name == null)
builder.Name = method.Name;

var parameters = method.GetParameters();
int pos = 0, count = parameters.Length;
foreach (var paramInfo in parameters)


+ 2
- 2
src/Discord.Net.Commands/CommandService.cs View File

@@ -19,8 +19,8 @@ namespace Discord.Commands
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
private readonly CommandMap _map;

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()
{


+ 1
- 1
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -42,7 +42,7 @@ namespace Discord.Commands

// 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) => second != null ? first + " " + second : first).ToImmutableArray();
// only module provides aliases
else if (module.Aliases.Count > 0)
Aliases = module.Aliases.ToImmutableArray();


Loading…
Cancel
Save