From 8c0d4b6123c15b3f5e26eecf5c16bc08e63749bc Mon Sep 17 00:00:00 2001 From: Finite Reality Date: Tue, 2 Aug 2016 21:05:11 +0100 Subject: [PATCH] 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;