Cache the current application on DiscordSocketClient
This commit is contained in:
@@ -13,12 +13,9 @@ namespace Discord.Commands
|
|||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||||
public class RequireOwnerAttribute : PreconditionAttribute
|
public class RequireOwnerAttribute : PreconditionAttribute
|
||||||
{
|
{
|
||||||
private IApplication application;
|
|
||||||
|
|
||||||
public override async Task<PreconditionResult> CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map)
|
public override async Task<PreconditionResult> CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map)
|
||||||
{
|
{
|
||||||
if (application == null)
|
var application = await context.Client.GetApplicationInfoAsync();
|
||||||
application = await context.Client.GetApplicationInfoAsync();
|
|
||||||
if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess();
|
if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess();
|
||||||
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
|
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace Discord.WebSocket
|
|||||||
private int _nextAudioId;
|
private int _nextAudioId;
|
||||||
private bool _canReconnect;
|
private bool _canReconnect;
|
||||||
private DateTimeOffset? _statusSince;
|
private DateTimeOffset? _statusSince;
|
||||||
|
private RestApplication _application;
|
||||||
|
|
||||||
/// <summary> Gets the shard of of this client. </summary>
|
/// <summary> Gets the shard of of this client. </summary>
|
||||||
public int ShardId { get; }
|
public int ShardId { get; }
|
||||||
@@ -333,8 +334,10 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task<RestApplication> GetApplicationInfoAsync()
|
public async Task<RestApplication> GetApplicationInfoAsync()
|
||||||
=> ClientHelper.GetApplicationInfoAsync(this);
|
{
|
||||||
|
return _application ?? (_application = await ClientHelper.GetApplicationInfoAsync(this));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public SocketGuild GetGuild(ulong id)
|
public SocketGuild GetGuild(ulong id)
|
||||||
|
|||||||
Reference in New Issue
Block a user