Skip to content

Commit

Permalink
Merge pull request #206 from FiniteReality/issue/203
Browse files Browse the repository at this point in the history
Add NameAttribute for overriding Name in commands/modules
  • Loading branch information
Auralytical committed Aug 18, 2016
2 parents 6d766d5 + 252d890 commit 06e81cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Discord.Net.Commands/Attributes/NameAttribute.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 4 additions & 0 deletions src/Discord.Net.Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ internal Command(MethodInfo source, Module module, object instance, CommandAttri
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;
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.Commands/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ internal Module(TypeInfo source, CommandService service, object instance, Module
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;
Expand Down

0 comments on commit 06e81cb

Please sign in to comment.