@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Parameter)]
|
// Full summary of method
|
||||||
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
|
||||||
public class DescriptionAttribute : Attribute
|
public class DescriptionAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
@@ -12,11 +13,12 @@ namespace Discord.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
// Brief summary of method/module/parameter
|
||||||
public class SynopsisAttribute : Attribute
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)]
|
||||||
|
public class SummaryAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
public SynopsisAttribute(string text)
|
public SummaryAttribute(string text)
|
||||||
{
|
{
|
||||||
Text = text;
|
Text = text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public string Description { get; }
|
public string Description { get; }
|
||||||
public string Synopsis { get; }
|
public string Summary { get; }
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
public Module Module { get; }
|
public Module Module { get; }
|
||||||
public IReadOnlyList<CommandParameter> Parameters { get; }
|
public IReadOnlyList<CommandParameter> Parameters { get; }
|
||||||
@@ -33,9 +33,9 @@ namespace Discord.Commands
|
|||||||
if (description != null)
|
if (description != null)
|
||||||
Description = description.Text;
|
Description = description.Text;
|
||||||
|
|
||||||
var synopsis = methodInfo.GetCustomAttribute<SynopsisAttribute>();
|
var summary = methodInfo.GetCustomAttribute<SummaryAttribute>();
|
||||||
if (synopsis != null)
|
if (summary != null)
|
||||||
Synopsis = synopsis.Text;
|
Summary = summary.Text;
|
||||||
|
|
||||||
Parameters = BuildParameters(methodInfo);
|
Parameters = BuildParameters(methodInfo);
|
||||||
Preconditions = BuildPreconditions(methodInfo);
|
Preconditions = BuildPreconditions(methodInfo);
|
||||||
@@ -129,11 +129,11 @@ 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 summary = 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;
|
||||||
|
|
||||||
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();
|
return paramBuilder.ToImmutable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,17 @@ namespace Discord.Commands
|
|||||||
private readonly TypeReader _reader;
|
private readonly TypeReader _reader;
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public string Description { get; }
|
public string Summary { get; }
|
||||||
public bool IsOptional { get; }
|
public bool IsOptional { get; }
|
||||||
public bool IsRemainder { get; }
|
public bool IsRemainder { get; }
|
||||||
public bool IsMultiple { get; }
|
public bool IsMultiple { get; }
|
||||||
public Type Type { get; }
|
public Type Type { get; }
|
||||||
internal object DefaultValue { 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;
|
Name = name;
|
||||||
Description = description;
|
Summary = summary;
|
||||||
Type = type;
|
Type = type;
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
IsOptional = isOptional;
|
IsOptional = isOptional;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace Discord.Commands
|
|||||||
{
|
{
|
||||||
public CommandService Service { get; }
|
public CommandService Service { get; }
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string Summary { get; }
|
||||||
|
public string Description { get; }
|
||||||
public IEnumerable<Command> Commands { get; }
|
public IEnumerable<Command> Commands { get; }
|
||||||
internal object Instance { get; }
|
internal object Instance { get; }
|
||||||
|
|
||||||
@@ -21,6 +23,14 @@ namespace Discord.Commands
|
|||||||
Name = typeInfo.Name;
|
Name = typeInfo.Name;
|
||||||
Instance = instance;
|
Instance = instance;
|
||||||
|
|
||||||
|
var summaryAttr = typeInfo.GetCustomAttribute<SummaryAttribute>();
|
||||||
|
if (summaryAttr != null)
|
||||||
|
Summary = summaryAttr.Text;
|
||||||
|
|
||||||
|
var descriptionAttr = typeInfo.GetCustomAttribute<DescriptionAttribute>();
|
||||||
|
if (descriptionAttr != null)
|
||||||
|
Description = descriptionAttr.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