Auto adding requirements to help description

This commit is contained in:
Kwoth 2016-10-09 05:01:56 +02:00
parent b69f416295
commit 19d67e3c2f
4 changed files with 22 additions and 3 deletions

View File

@ -484,6 +484,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.Administrator)]
[OwnerOnly] [OwnerOnly]
public async Task LogServer(IUserMessage msg) public async Task LogServer(IUserMessage msg)
{ {
@ -507,6 +508,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.Administrator)]
[OwnerOnly] [OwnerOnly]
public async Task LogIgnore(IUserMessage imsg) public async Task LogIgnore(IUserMessage imsg)
{ {
@ -602,6 +604,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.Administrator)]
public async Task UserPresence(IUserMessage imsg) public async Task UserPresence(IUserMessage imsg)
{ {
var channel = (ITextChannel)imsg.Channel; var channel = (ITextChannel)imsg.Channel;
@ -624,6 +627,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.Administrator)]
public async Task VoicePresence(IUserMessage imsg) public async Task VoicePresence(IUserMessage imsg)
{ {
var channel = (ITextChannel)imsg.Channel; var channel = (ITextChannel)imsg.Channel;

View File

@ -109,10 +109,25 @@ namespace NadekoBot.Modules.Help
if (alias != null) if (alias != null)
str += $" / `{ alias }`"; str += $" / `{ alias }`";
if (com != null) if (com != null)
await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {com.Summary} await channel.SendMessageAsync(str + $@"{Environment.NewLine}**Desc:** {com.Summary} {GetCommandRequirements(com)}
**Usage:** {com.Remarks}").ConfigureAwait(false); **Usage:** {com.Remarks}").ConfigureAwait(false);
} }
private string GetCommandRequirements(Command cmd)
{
return String.Join(" ", cmd.Source.CustomAttributes
.Where(ca => ca.AttributeType == typeof(OwnerOnlyAttribute) || ca.AttributeType == typeof(RequirePermissionAttribute))
.Select(ca =>
{
if (ca.AttributeType == typeof(OwnerOnlyAttribute))
return "**Bot owner only.**";
else if (ca.AttributeType == typeof(RequirePermissionAttribute))
return $"**Requires {(GuildPermission)ca.ConstructorArguments.FirstOrDefault().Value} server permission.**".Replace("Guild", "Server");
else
return $"**Requires {(GuildPermission)ca.ConstructorArguments.FirstOrDefault().Value} channel permission.**".Replace("Guild", "Server");
}));
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[OwnerOnly] [OwnerOnly]

View File

@ -5802,7 +5802,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to `.send sid. /// Looks up a localized string similar to `.send sid`.
/// </summary> /// </summary>
public static string send_usage { public static string send_usage {
get { get {

View File

@ -763,7 +763,7 @@
<value>Send a message to someone on a different server through the bot. </value> <value>Send a message to someone on a different server through the bot. </value>
</data> </data>
<data name="send_usage" xml:space="preserve"> <data name="send_usage" xml:space="preserve">
<value>`.send sid</value> <value>`.send sid`</value>
</data> </data>
<data name="mentionrole_cmd" xml:space="preserve"> <data name="mentionrole_cmd" xml:space="preserve">
<value>mentionrole menro</value> <value>mentionrole menro</value>