Add Command and module instance parameters to CheckPermissions
After a small discussion with Joe4evr on discord, a way of retrieving the state of a module appeared to be needed. The new override should provide enough context to a bot dev to allow them to do what they want.
This commit is contained in:
@@ -8,6 +8,6 @@ namespace Discord.Commands
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
|
||||
public abstract class PreconditionAttribute : Attribute
|
||||
{
|
||||
public abstract Task<PreconditionResult> CheckPermissions(IMessage context);
|
||||
public abstract Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Discord.Commands
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class RequireDMAttribute : PreconditionAttribute
|
||||
{
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context)
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
||||
{
|
||||
if (context.Channel is IGuildChannel)
|
||||
return Task.FromResult(PreconditionResult.FromError("Command must be used in a DM"));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Discord.Commands
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class RequireGuildAttribute : PreconditionAttribute
|
||||
{
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context)
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
||||
{
|
||||
if (!(context.Channel is IGuildChannel))
|
||||
return Task.FromResult(PreconditionResult.FromError("Command must be used in a guild"));
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace Discord.Commands.Attributes.Preconditions
|
||||
GuildPermission = null;
|
||||
}
|
||||
|
||||
public override async Task<PreconditionResult> CheckPermissions(IMessage context)
|
||||
public override async Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
||||
{
|
||||
var result = await base.CheckPermissions(context).ConfigureAwait(false);
|
||||
var result = await base.CheckPermissions(context, executingCommand, moduleInstance).ConfigureAwait(false);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace Discord.Commands
|
||||
Comparer = comparer;
|
||||
}
|
||||
|
||||
public override async Task<PreconditionResult> CheckPermissions(IMessage context)
|
||||
public override async Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
||||
{
|
||||
var result = await base.CheckPermissions(context).ConfigureAwait(false);
|
||||
var result = await base.CheckPermissions(context, executingCommand, moduleInstance).ConfigureAwait(false);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
|
||||
@@ -46,14 +46,14 @@ namespace Discord.Commands
|
||||
{
|
||||
foreach (PreconditionAttribute precondition in Module.Preconditions)
|
||||
{
|
||||
var result = await precondition.CheckPermissions(context).ConfigureAwait(false);
|
||||
var result = await precondition.CheckPermissions(context, this, Module.Instance).ConfigureAwait(false);
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (PreconditionAttribute precondition in Preconditions)
|
||||
{
|
||||
var result = await precondition.CheckPermissions(context).ConfigureAwait(false);
|
||||
var result = await precondition.CheckPermissions(context, this, Module.Instance).ConfigureAwait(false);
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user