Browse Source

Improve command documentation features

pull/178/head
Finite Reality 9 years ago
parent
commit
8c0d4b6123
3 changed files with 9 additions and 2 deletions
  1. +3
    -1
      src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs
  2. +1
    -1
      src/Discord.Net.Commands/Command.cs
  3. +5
    -0
      src/Discord.Net.Commands/Module.cs

+ 3
- 1
src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs View File

@@ -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; }


+ 1
- 1
src/Discord.Net.Commands/Command.cs View File

@@ -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;



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

@@ -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;


Loading…
Cancel
Save