Browse Source

added a flag "forceWhitespace" on module attribute to opt out of forced whitespaces after prefix

pull/193/head
Kwoth 9 years ago
parent
commit
180a909076
2 changed files with 9 additions and 11 deletions
  1. +5
    -7
      src/Discord.Net.Commands/Attributes/ModuleAttribute.cs
  2. +4
    -4
      src/Discord.Net.Commands/Module.cs

+ 5
- 7
src/Discord.Net.Commands/Attributes/ModuleAttribute.cs View File

@@ -6,16 +6,14 @@ namespace Discord.Commands
public class ModuleAttribute : Attribute
{
public string Prefix { get; }
public bool AutoLoad { get; set; }
public ModuleAttribute()
{
Prefix = null;
AutoLoad = true;
}
public ModuleAttribute(string prefix)
public bool AutoLoad { get; }
public bool ForceWhitespace { get; }

public ModuleAttribute(string prefix = null)
{
Prefix = prefix;
AutoLoad = true;
ForceWhitespace = true;
}
}
}

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

@@ -34,15 +34,15 @@ namespace Discord.Commands
Description = descriptionAttr.Text;

List<Command> commands = new List<Command>();
SearchClass(source, instance, commands, moduleAttr.Prefix ?? "");
SearchClass(source, instance, commands, moduleAttr.Prefix ?? "", moduleAttr.ForceWhitespace);
Commands = commands;

Preconditions = BuildPreconditions();
}

private void SearchClass(TypeInfo parentType, object instance, List<Command> commands, string groupPrefix)
private void SearchClass(TypeInfo parentType, object instance, List<Command> commands, string groupPrefix, bool forceWhitespace)
{
if (groupPrefix != "")
if (groupPrefix != "" && forceWhitespace)
groupPrefix += " ";
foreach (var method in parentType.DeclaredMethods)
{
@@ -60,7 +60,7 @@ namespace Discord.Commands
nextGroupPrefix = groupPrefix + groupAttrib.Prefix ?? type.Name;
else
nextGroupPrefix = groupPrefix;
SearchClass(type, ReflectionUtils.CreateObject(type, Service), commands, nextGroupPrefix);
SearchClass(type, ReflectionUtils.CreateObject(type, Service), commands, nextGroupPrefix, forceWhitespace);
}
}
}


Loading…
Cancel
Save