Browse Source

Fix RequireOwner Precon. ignoring team members

pull/2273/head
exsersewo 3 years ago
parent
commit
eea0177978
No known key found for this signature in database GPG Key ID: 9C6DDF9AC9BA14A0
2 changed files with 22 additions and 4 deletions
  1. +11
    -2
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +11
    -2
      src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs

+ 11
- 2
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -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)}.");


+ 11
- 2
src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -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)}.");


Loading…
Cancel
Save