From e71708f5e8fff21c63b53cbdfb12c23f8b396f95 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 15 Jan 2023 00:50:25 +0100 Subject: [PATCH] .h command show now properly show both channel and server user permission requirements --- src/NadekoBot/Common/Attributes/UserPerm.cs | 2 +- src/NadekoBot/Modules/Help/HelpService.cs | 24 ++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/NadekoBot/Common/Attributes/UserPerm.cs b/src/NadekoBot/Common/Attributes/UserPerm.cs index 5ea5257b2..31087cb2e 100644 --- a/src/NadekoBot/Common/Attributes/UserPerm.cs +++ b/src/NadekoBot/Common/Attributes/UserPerm.cs @@ -3,7 +3,7 @@ using NadekoBot.Modules.Administration.Services; namespace Discord; -[AttributeUsage(AttributeTargets.Method)] +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class UserPermAttribute : RequireUserPermissionAttribute { public UserPermAttribute(GuildPerm permission) diff --git a/src/NadekoBot/Modules/Help/HelpService.cs b/src/NadekoBot/Modules/Help/HelpService.cs index 87203776f..0a8d8efaa 100644 --- a/src/NadekoBot/Modules/Help/HelpService.cs +++ b/src/NadekoBot/Modules/Help/HelpService.cs @@ -152,18 +152,22 @@ public class HelpService : IExecNoCommand, INService .Any(x => x is OnlyPublicBotAttribute)) toReturn.Add("Only Public Bot"); - var userPerm = (UserPermAttribute)cmd.Preconditions.FirstOrDefault(ca => ca is UserPermAttribute); + var userPermString = cmd.Preconditions + .Where(ca => ca is UserPermAttribute) + .Cast() + .Select(userPerm => + { + if (userPerm.ChannelPermission is { } cPerm) + return GetPreconditionString(cPerm); - var userPermString = string.Empty; - if (userPerm is not null) - { - if (userPerm.ChannelPermission is { } cPerm) - userPermString = GetPreconditionString(cPerm); - - if (userPerm.GuildPermission is { } gPerm) - userPermString = GetPreconditionString(gPerm); - } + if (userPerm.GuildPermission is { } gPerm) + return GetPreconditionString(gPerm); + return string.Empty; + }) + .Where(x => !string.IsNullOrWhiteSpace(x)) + .Join('\n'); + if (overrides is null) { if (!string.IsNullOrWhiteSpace(userPermString))