From eea0177978f49dfb1d4febf5cb260f0ef8333cd3 Mon Sep 17 00:00:00 2001 From: exsersewo Date: Fri, 29 Apr 2022 20:29:03 +0100 Subject: [PATCH] Fix RequireOwner Precon. ignoring team members --- .../Preconditions/RequireOwnerAttribute.cs | 13 +++++++++++-- .../Preconditions/RequireOwnerAttribute.cs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs index c08e1e9da..bbbc553f5 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; namespace Discord.Commands @@ -44,8 +45,16 @@ namespace Discord.Commands { case TokenType.Bot: var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false); - if (context.User.Id != application.Owner.Id) - return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + if (application.Owner.PublicFlags.HasValue && (application.Owner.PublicFlags.Value & UserProperties.TeamUser) != 0) + { + if (application.Team.TeamMembers.All(tm => tm.User.Id != context.User.Id)) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by an owner of the bot."); + } + else + { + if (context.User.Id != application.Owner.Id) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + } return PreconditionResult.FromSuccess(); default: return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}."); diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs index 827ede239..8f4cca899 100644 --- a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; namespace Discord.Interactions @@ -25,8 +26,16 @@ namespace Discord.Interactions { case TokenType.Bot: var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false); - if (context.User.Id != application.Owner.Id) - return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + if (application.Owner.PublicFlags.HasValue && (application.Owner.PublicFlags.Value & UserProperties.TeamUser) != 0) + { + if (application.Team.TeamMembers.All(tm => tm.User.Id != context.User.Id)) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by an owner of the bot."); + } + else + { + if (context.User.Id != application.Owner.Id) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + } return PreconditionResult.FromSuccess(); default: return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}.");