From 1ed4f703bf61b9ab8af7c3d64d266154265fc236 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 26 Nov 2016 14:59:20 -0500 Subject: [PATCH] Cache the current application on DiscordSocketClient --- .../Attributes/Preconditions/RequireOwnerAttribute.cs | 5 +---- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs index beb8dfdd0..8992cd115 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs @@ -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 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"); } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 3eb4158d1..8c6a37f3c 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -38,6 +38,7 @@ namespace Discord.WebSocket private int _nextAudioId; private bool _canReconnect; private DateTimeOffset? _statusSince; + private RestApplication _application; /// Gets the shard of of this client. public int ShardId { get; } @@ -333,8 +334,10 @@ namespace Discord.WebSocket } /// - public Task GetApplicationInfoAsync() - => ClientHelper.GetApplicationInfoAsync(this); + public async Task GetApplicationInfoAsync() + { + return _application ?? (_application = await ClientHelper.GetApplicationInfoAsync(this)); + } /// public SocketGuild GetGuild(ulong id)