Merge pull request #206 from FiniteReality/issue/203
Add NameAttribute for overriding Name in commands/modules
This commit is contained in:
15
src/Discord.Net.Commands/Attributes/NameAttribute.cs
Normal file
15
src/Discord.Net.Commands/Attributes/NameAttribute.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
// Override public name of command/module
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
|
||||
public class NameAttribute : Attribute
|
||||
{
|
||||
public string Text { get; }
|
||||
public NameAttribute(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,10 @@ namespace Discord.Commands
|
||||
Name = source.Name;
|
||||
Text = groupPrefix + attribute.Text;
|
||||
|
||||
var nameAttr = source.GetCustomAttribute<NameAttribute>();
|
||||
if (nameAttr != null)
|
||||
Name = nameAttr.Text;
|
||||
|
||||
var description = source.GetCustomAttribute<DescriptionAttribute>();
|
||||
if (description != null)
|
||||
Description = description.Text;
|
||||
|
||||
@@ -25,6 +25,10 @@ namespace Discord.Commands
|
||||
Name = source.Name;
|
||||
Instance = instance;
|
||||
|
||||
var nameAttr = source.GetCustomAttribute<NameAttribute>();
|
||||
if (nameAttr != null)
|
||||
Name = nameAttr.Text;
|
||||
|
||||
var summaryAttr = source.GetCustomAttribute<SummaryAttribute>();
|
||||
if (summaryAttr != null)
|
||||
Summary = summaryAttr.Text;
|
||||
|
||||
Reference in New Issue
Block a user