From 180a909076917f4d57767a56c4aa39bdc41bd51e Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 12 Aug 2016 17:21:18 +0200 Subject: [PATCH 1/3] added a flag "forceWhitespace" on module attribute to opt out of forced whitespaces after prefix --- .../Attributes/ModuleAttribute.cs | 12 +++++------- src/Discord.Net.Commands/Module.cs | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs index ec04041e8..3a5d9363e 100644 --- a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs @@ -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; } } } diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index f965d78ab..1dcd95801 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -34,15 +34,15 @@ namespace Discord.Commands Description = descriptionAttr.Text; List commands = new List(); - 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 commands, string groupPrefix) + private void SearchClass(TypeInfo parentType, object instance, List 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); } } } From ff19727517f54f70fba7e3e5232d5ae43429fa79 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 12 Aug 2016 17:26:09 +0200 Subject: [PATCH 2/3] Brought back deleted setters --- src/Discord.Net.Commands/Attributes/ModuleAttribute.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs index 3a5d9363e..0ed43db3c 100644 --- a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs @@ -6,8 +6,8 @@ namespace Discord.Commands public class ModuleAttribute : Attribute { public string Prefix { get; } - public bool AutoLoad { get; } - public bool ForceWhitespace { get; } + public bool AutoLoad { get; set; } + public bool ForceWhitespace { get; set; } public ModuleAttribute(string prefix = null) { From cf911456a751f4778fe4789973e028560624cfe8 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 13 Aug 2016 04:18:05 +0200 Subject: [PATCH 3/3] Default constructor back, name changed to AppendWhitespace --- src/Discord.Net.Commands/Attributes/ModuleAttribute.cs | 6 ++++-- src/Discord.Net.Commands/Module.cs | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs index 0ed43db3c..1bf83dbc0 100644 --- a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs @@ -7,13 +7,15 @@ namespace Discord.Commands { public string Prefix { get; } public bool AutoLoad { get; set; } - public bool ForceWhitespace { get; set; } + public bool AppendSpace { get; set; } + + public ModuleAttribute() : this(null) { } public ModuleAttribute(string prefix = null) { Prefix = prefix; AutoLoad = true; - ForceWhitespace = true; + AppendSpace = true; } } } diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 1dcd95801..565e9699d 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -34,15 +34,15 @@ namespace Discord.Commands Description = descriptionAttr.Text; List commands = new List(); - SearchClass(source, instance, commands, moduleAttr.Prefix ?? "", moduleAttr.ForceWhitespace); + SearchClass(source, instance, commands, moduleAttr.Prefix ?? "", moduleAttr.AppendSpace); Commands = commands; Preconditions = BuildPreconditions(); } - private void SearchClass(TypeInfo parentType, object instance, List commands, string groupPrefix, bool forceWhitespace) + private void SearchClass(TypeInfo parentType, object instance, List commands, string groupPrefix, bool appendWhitespace) { - if (groupPrefix != "" && forceWhitespace) + if (groupPrefix != "" && appendWhitespace) 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, forceWhitespace); + SearchClass(type, ReflectionUtils.CreateObject(type, Service), commands, nextGroupPrefix, appendWhitespace); } } }