Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Aliasses, Summary and Remarks Properties to CommandAttribute #2700

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Discord.Net.Commands/Attributes/CommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ public class CommandAttribute : Attribute
public RunMode RunMode { get; set; } = RunMode.Default;
public bool? IgnoreExtraArgs { get; }

/// <summary>
/// Attaches a summary to your command.
/// </summary>
/// <remarks>
/// <see cref="Summary"/> overrides the value of this property if present.
/// </remarks>
public string Summary { get; set; }

/// <summary>
/// Marks the aliases for a command.
/// </summary>
/// <remarks>
/// <see cref="AliasAttribute"/> extends the base value of this if present.
/// </remarks>
public string[] Aliases { get; set; }

/// <summary>
/// Attaches remarks to your commands.
/// </summary>
/// <remarks>
/// <see cref="RemainderAttribute"/> overrides the value of this property if present.
/// </remarks>
public string Remarks { get; set; }

/// <inheritdoc />
public CommandAttribute()
{
Expand All @@ -32,10 +56,20 @@ public CommandAttribute(string text)
{
Text = text;
}

public CommandAttribute(string text, bool ignoreExtraArgs)
{
Text = text;
IgnoreExtraArgs = ignoreExtraArgs;
}

public CommandAttribute(string text, bool ignoreExtraArgs, string summary = default, string[] aliases = default, string remarks = default)
{
Text = text;
IgnoreExtraArgs = ignoreExtraArgs;
Summary = summary;
Aliases = aliases;
Remarks = remarks;
}
}
}
3 changes: 3 additions & 0 deletions src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ private static void BuildCommand(CommandBuilder builder, TypeInfo typeInfo, Meth
switch (attribute)
{
case CommandAttribute command:
builder.Summary ??= command.Summary;
builder.Remarks ??= command.Remarks;
builder.AddAliases(command.Aliases ?? Array.Empty<string>());
builder.AddAliases(command.Text);
builder.RunMode = command.RunMode;
builder.Name ??= command.Text;
Expand Down