Browse Source

Cache the current application on DiscordSocketClient

tags/1.0-rc
Christopher F 8 years ago
parent
commit
1ed4f703bf
2 changed files with 6 additions and 6 deletions
  1. +1
    -4
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +5
    -2
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 1
- 4
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -13,12 +13,9 @@ namespace Discord.Commands
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class RequireOwnerAttribute : PreconditionAttribute
{
private IApplication application;

public override async Task<PreconditionResult> CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map)
{
if (application == null)
application = await context.Client.GetApplicationInfoAsync();
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");
}


+ 5
- 2
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -38,6 +38,7 @@ namespace Discord.WebSocket
private int _nextAudioId;
private bool _canReconnect;
private DateTimeOffset? _statusSince;
private RestApplication _application;

/// <summary> Gets the shard of of this client. </summary>
public int ShardId { get; }
@@ -333,8 +334,10 @@ namespace Discord.WebSocket
}

/// <inheritdoc />
public Task<RestApplication> GetApplicationInfoAsync()
=> ClientHelper.GetApplicationInfoAsync(this);
public async Task<RestApplication> GetApplicationInfoAsync()
{
return _application ?? (_application = await ClientHelper.GetApplicationInfoAsync(this));
}

/// <inheritdoc />
public SocketGuild GetGuild(ulong id)


Loading…
Cancel
Save