Improve command documentation features
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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<DescriptionAttribute>()?.Text;
|
||||
string description = parameter.GetCustomAttribute<DescriptionAttribute>()?.Text;
|
||||
bool isOptional = parameter.IsOptional;
|
||||
object defaultValue = parameter.HasDefaultValue ? parameter.DefaultValue : null;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Discord.Commands
|
||||
{
|
||||
public CommandService Service { get; }
|
||||
public string Name { get; }
|
||||
public string Synopsis { get; }
|
||||
public IEnumerable<Command> Commands { get; }
|
||||
internal object Instance { get; }
|
||||
|
||||
@@ -18,6 +19,10 @@ namespace Discord.Commands
|
||||
Name = typeInfo.Name;
|
||||
Instance = instance;
|
||||
|
||||
var synopsisAttr = typeInfo.GetCustomAttribute<SynopsisAttribute>();
|
||||
if (synopsisAttr != null)
|
||||
Synopsis = synopsisAttr.Text;
|
||||
|
||||
List<Command> commands = new List<Command>();
|
||||
SearchClass(instance, commands, typeInfo, moduleAttr.Prefix ?? "");
|
||||
Commands = commands;
|
||||
|
||||
Reference in New Issue
Block a user