From 3856d435876b4aab3833ba09fe2c878071be3a0a Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Tue, 2 Aug 2016 19:54:00 +0100 Subject: [PATCH 1/5] Remove Modules enumerable, change Commands to ILookup --- src/Discord.Net.Commands/CommandService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 2ce7c5517..3ecd77c1d 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -16,8 +16,7 @@ namespace Discord.Commands private readonly ConcurrentDictionary _typeReaders; private readonly CommandMap _map; - public IEnumerable Modules => _modules.Select(x => x.Value); - public IEnumerable Commands => _modules.SelectMany(x => x.Value.Commands); + public ILookup Commands => _modules.SelectMany(x => x.Value.Commands).ToLookup(x => x.Module); public CommandService() { From 8c0d4b6123c15b3f5e26eecf5c16bc08e63749bc Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Tue, 2 Aug 2016 21:05:11 +0100 Subject: [PATCH 2/5] Improve command documentation features --- src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs | 4 +++- src/Discord.Net.Commands/Command.cs | 2 +- src/Discord.Net.Commands/Module.cs | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs index db9c57057..3a6942086 100644 --- a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs @@ -2,6 +2,7 @@ namespace Discord.Commands { + // Full summary of method/parameter [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)] public class DescriptionAttribute : Attribute { @@ -12,7 +13,8 @@ namespace Discord.Commands } } - [AttributeUsage(AttributeTargets.Method)] + // Brief summary of method/module + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] public class SynopsisAttribute : Attribute { public string Text { get; } diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index 5729e4c81..e49245c49 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -103,7 +103,7 @@ namespace Discord.Commands throw new InvalidOperationException("Remainder parameters must be the last parameter in a command."); string name = parameter.Name; - string description = typeInfo.GetCustomAttribute()?.Text; + string description = parameter.GetCustomAttribute()?.Text; bool isOptional = parameter.IsOptional; object defaultValue = parameter.HasDefaultValue ? parameter.DefaultValue : null; diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index b884832bc..e2b44c8bb 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -9,6 +9,7 @@ namespace Discord.Commands { public CommandService Service { get; } public string Name { get; } + public string Synopsis { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -18,6 +19,10 @@ namespace Discord.Commands Name = typeInfo.Name; Instance = instance; + var synopsisAttr = typeInfo.GetCustomAttribute(); + if (synopsisAttr != null) + Synopsis = synopsisAttr.Text; + List commands = new List(); SearchClass(instance, commands, typeInfo, moduleAttr.Prefix ?? ""); Commands = commands; From 47089448dda3f15c791dd7db6625c0e64bdcc07c Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Wed, 3 Aug 2016 16:33:26 +0100 Subject: [PATCH 3/5] Fix Synopsis/Description mix-up --- src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs | 8 ++++---- src/Discord.Net.Commands/Module.cs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs index 3a6942086..397d97512 100644 --- a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs @@ -2,8 +2,8 @@ namespace Discord.Commands { - // Full summary of method/parameter - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)] + // Full summary of method + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] public class DescriptionAttribute : Attribute { public string Text { get; } @@ -13,8 +13,8 @@ namespace Discord.Commands } } - // Brief summary of method/module - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] + // Brief summary of method/module/parameter + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] public class SynopsisAttribute : Attribute { public string Text { get; } diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index e2b44c8bb..50b48f37c 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -10,6 +10,7 @@ namespace Discord.Commands public CommandService Service { get; } public string Name { get; } public string Synopsis { get; } + public string Description { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -23,6 +24,10 @@ namespace Discord.Commands if (synopsisAttr != null) Synopsis = synopsisAttr.Text; + var descriptionAttr = typeInfo.GetCustomAttribute(); + if (descriptionAttr != null) + Description = descriptionAttr.Text; + List commands = new List(); SearchClass(instance, commands, typeInfo, moduleAttr.Prefix ?? ""); Commands = commands; From 86092f9253a901148254aa521e4c4869a35f2248 Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Fri, 5 Aug 2016 00:17:29 +0100 Subject: [PATCH 4/5] Rename Synopsis to Summary to improve clarity --- src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs | 4 ++-- src/Discord.Net.Commands/Command.cs | 8 ++++---- src/Discord.Net.Commands/Module.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs index 397d97512..efa5f42a4 100644 --- a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs @@ -15,10 +15,10 @@ namespace Discord.Commands // Brief summary of method/module/parameter [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] - public class SynopsisAttribute : Attribute + public class SummaryAttribute : Attribute { public string Text { get; } - public SynopsisAttribute(string text) + public SummaryAttribute(string text) { Text = text; } diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index e49245c49..fe5352478 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -15,7 +15,7 @@ namespace Discord.Commands public string Name { get; } public string Description { get; } - public string Synopsis { get; } + public string Summary { get; } public string Text { get; } public Module Module { get; } public IReadOnlyList Parameters { get; } @@ -32,9 +32,9 @@ namespace Discord.Commands if (description != null) Description = description.Text; - var synopsis = methodInfo.GetCustomAttribute(); - if (synopsis != null) - Synopsis = synopsis.Text; + var summary = methodInfo.GetCustomAttribute(); + if (summary != null) + Summary = summary.Text; Parameters = BuildParameters(methodInfo); _action = BuildAction(methodInfo); diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 50b48f37c..8c75d3ea7 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -9,7 +9,7 @@ namespace Discord.Commands { public CommandService Service { get; } public string Name { get; } - public string Synopsis { get; } + public string Summary { get; } public string Description { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -20,9 +20,9 @@ namespace Discord.Commands Name = typeInfo.Name; Instance = instance; - var synopsisAttr = typeInfo.GetCustomAttribute(); - if (synopsisAttr != null) - Synopsis = synopsisAttr.Text; + var summaryAttr = typeInfo.GetCustomAttribute(); + if (summaryAttr != null) + Summary = summaryAttr.Text; var descriptionAttr = typeInfo.GetCustomAttribute(); if (descriptionAttr != null) From f7633ea3d7cfdcff160a8c8241f5b0060bff3987 Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Tue, 9 Aug 2016 16:37:56 +0100 Subject: [PATCH 5/5] Revert 3856d43 & rename CommandParameter.Description to Summary --- src/Discord.Net.Commands/Command.cs | 4 ++-- src/Discord.Net.Commands/CommandParameter.cs | 6 +++--- src/Discord.Net.Commands/CommandService.cs | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index fe5352478..5d81e0924 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -103,11 +103,11 @@ namespace Discord.Commands throw new InvalidOperationException("Remainder parameters must be the last parameter in a command."); string name = parameter.Name; - string description = parameter.GetCustomAttribute()?.Text; + string summary = parameter.GetCustomAttribute()?.Text; bool isOptional = parameter.IsOptional; object defaultValue = parameter.HasDefaultValue ? parameter.DefaultValue : null; - paramBuilder.Add(new CommandParameter(name, description, type, reader, isOptional, isRemainder, isMultiple, defaultValue)); + paramBuilder.Add(new CommandParameter(name, summary, type, reader, isOptional, isRemainder, isMultiple, defaultValue)); } return paramBuilder.ToImmutable(); } diff --git a/src/Discord.Net.Commands/CommandParameter.cs b/src/Discord.Net.Commands/CommandParameter.cs index f18b1a13b..f0b6f16b3 100644 --- a/src/Discord.Net.Commands/CommandParameter.cs +++ b/src/Discord.Net.Commands/CommandParameter.cs @@ -10,17 +10,17 @@ namespace Discord.Commands private readonly TypeReader _reader; public string Name { get; } - public string Description { get; } + public string Summary { get; } public bool IsOptional { get; } public bool IsRemainder { get; } public bool IsMultiple { get; } public Type Type { get; } internal object DefaultValue { get; } - public CommandParameter(string name, string description, Type type, TypeReader reader, bool isOptional, bool isRemainder, bool isMultiple, object defaultValue) + public CommandParameter(string name, string summary, Type type, TypeReader reader, bool isOptional, bool isRemainder, bool isMultiple, object defaultValue) { Name = name; - Description = description; + Summary = summary; Type = type; _reader = reader; IsOptional = isOptional; diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 3ecd77c1d..2ce7c5517 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -16,7 +16,8 @@ namespace Discord.Commands private readonly ConcurrentDictionary _typeReaders; private readonly CommandMap _map; - public ILookup Commands => _modules.SelectMany(x => x.Value.Commands).ToLookup(x => x.Module); + public IEnumerable Modules => _modules.Select(x => x.Value); + public IEnumerable Commands => _modules.SelectMany(x => x.Value.Commands); public CommandService() {