Browse Source

Allow parameterless commands to build correctly

Resolves #253
tags/1.0-rc
FiniteReality 8 years ago
parent
commit
1ab763e157
2 changed files with 15 additions and 3 deletions
  1. +9
    -1
      src/Discord.Net.Commands/Command.cs
  2. +6
    -2
      src/Discord.Net.Commands/Module.cs

+ 9
- 1
src/Discord.Net.Commands/Command.cs View File

@@ -38,7 +38,15 @@ namespace Discord.Commands
_instance = instance; _instance = instance;


Name = source.Name; Name = source.Name;
Text = groupPrefix + attribute.Text;

if (attribute.Text == null)
Text = groupPrefix;

if (groupPrefix != "")
groupPrefix += " ";

if (attribute.Text != null)
Text = groupPrefix + attribute.Text;


var aliasesBuilder = ImmutableArray.CreateBuilder<string>(); var aliasesBuilder = ImmutableArray.CreateBuilder<string>();




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

@@ -48,8 +48,6 @@ namespace Discord.Commands


private void SearchClass(TypeInfo parentType, object instance, List<Command> commands, string groupPrefix, IDependencyMap dependencyMap) private void SearchClass(TypeInfo parentType, object instance, List<Command> commands, string groupPrefix, IDependencyMap dependencyMap)
{ {
if (groupPrefix != "")
groupPrefix += " ";
foreach (var method in parentType.DeclaredMethods) foreach (var method in parentType.DeclaredMethods)
{ {
var cmdAttr = method.GetCustomAttribute<CommandAttribute>(); var cmdAttr = method.GetCustomAttribute<CommandAttribute>();
@@ -63,9 +61,15 @@ namespace Discord.Commands
{ {
string nextGroupPrefix; string nextGroupPrefix;
if (groupAttrib.Prefix != null) if (groupAttrib.Prefix != null)
{
if (groupPrefix != "")
groupPrefix += " ";
nextGroupPrefix = groupPrefix + groupAttrib.Prefix ?? type.Name; nextGroupPrefix = groupPrefix + groupAttrib.Prefix ?? type.Name;
}
else else
{
nextGroupPrefix = groupPrefix; nextGroupPrefix = groupPrefix;
}
SearchClass(type, ReflectionUtils.CreateObject(type, Service, dependencyMap), commands, nextGroupPrefix, dependencyMap); SearchClass(type, ReflectionUtils.CreateObject(type, Service, dependencyMap), commands, nextGroupPrefix, dependencyMap);
} }
} }


Loading…
Cancel
Save