Browse Source

Added RequireOwner support for User tokens

tags/1.0-rc
RogueException 8 years ago
parent
commit
683541ba24
3 changed files with 16 additions and 3 deletions
  1. +14
    -3
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +1
    -0
      src/Discord.Net.Core/IDiscordClient.cs
  3. +1
    -0
      src/Discord.Net.Rest/BaseDiscordClient.cs

+ 14
- 3
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -12,9 +12,20 @@ namespace Discord.Commands
{
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
{
var application = await context.Client.GetApplicationInfoAsync();
if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess();
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
switch (context.Client.TokenType)
{
case TokenType.Bot:
var application = await context.Client.GetApplicationInfoAsync();
if (context.User.Id != application.Owner.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
return PreconditionResult.FromSuccess();
case TokenType.User:
if (context.User.Id != context.Client.CurrentUser.Id)
return PreconditionResult.FromError("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)}.");
}
}
}
}

+ 1
- 0
src/Discord.Net.Core/IDiscordClient.cs View File

@@ -9,6 +9,7 @@ namespace Discord
{
ConnectionState ConnectionState { get; }
ISelfUser CurrentUser { get; }
TokenType TokenType { get; }

Task StartAsync();
Task StopAsync();


+ 1
- 0
src/Discord.Net.Rest/BaseDiscordClient.cs View File

@@ -26,6 +26,7 @@ namespace Discord.Rest
internal LogManager LogManager { get; }
public LoginState LoginState { get; private set; }
public ISelfUser CurrentUser { get; protected set; }
public TokenType TokenType => ApiClient.AuthTokenType;
/// <summary> Creates a new REST-only discord client. </summary>
internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client)


Loading…
Cancel
Save