Improve command documentation features
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
|
// Full summary of method/parameter
|
||||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
||||||
public class DescriptionAttribute : Attribute
|
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 class SynopsisAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace Discord.Commands
|
|||||||
throw new InvalidOperationException("Remainder parameters must be the last parameter in a command.");
|
throw new InvalidOperationException("Remainder parameters must be the last parameter in a command.");
|
||||||
|
|
||||||
string name = parameter.Name;
|
string name = parameter.Name;
|
||||||
string description = typeInfo.GetCustomAttribute<DescriptionAttribute>()?.Text;
|
string description = parameter.GetCustomAttribute<DescriptionAttribute>()?.Text;
|
||||||
bool isOptional = parameter.IsOptional;
|
bool isOptional = parameter.IsOptional;
|
||||||
object defaultValue = parameter.HasDefaultValue ? parameter.DefaultValue : null;
|
object defaultValue = parameter.HasDefaultValue ? parameter.DefaultValue : null;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Discord.Commands
|
|||||||
{
|
{
|
||||||
public CommandService Service { get; }
|
public CommandService Service { get; }
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string Synopsis { get; }
|
||||||
public IEnumerable<Command> Commands { get; }
|
public IEnumerable<Command> Commands { get; }
|
||||||
internal object Instance { get; }
|
internal object Instance { get; }
|
||||||
|
|
||||||
@@ -18,6 +19,10 @@ namespace Discord.Commands
|
|||||||
Name = typeInfo.Name;
|
Name = typeInfo.Name;
|
||||||
Instance = instance;
|
Instance = instance;
|
||||||
|
|
||||||
|
var synopsisAttr = typeInfo.GetCustomAttribute<SynopsisAttribute>();
|
||||||
|
if (synopsisAttr != null)
|
||||||
|
Synopsis = synopsisAttr.Text;
|
||||||
|
|
||||||
List<Command> commands = new List<Command>();
|
List<Command> commands = new List<Command>();
|
||||||
SearchClass(instance, commands, typeInfo, moduleAttr.Prefix ?? "");
|
SearchClass(instance, commands, typeInfo, moduleAttr.Prefix ?? "");
|
||||||
Commands = commands;
|
Commands = commands;
|
||||||
|
|||||||
Reference in New Issue
Block a user