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.tags/1.0-rc
| @@ -8,6 +8,6 @@ namespace Discord.Commands | |||||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||||
| public abstract class PreconditionAttribute : Attribute | 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)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
| public class RequireDMAttribute : PreconditionAttribute | 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) | if (context.Channel is IGuildChannel) | ||||
| return Task.FromResult(PreconditionResult.FromError("Command must be used in a DM")); | 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)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
| public class RequireGuildAttribute : PreconditionAttribute | 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)) | if (!(context.Channel is IGuildChannel)) | ||||
| return Task.FromResult(PreconditionResult.FromError("Command must be used in a guild")); | return Task.FromResult(PreconditionResult.FromError("Command must be used in a guild")); | ||||
| @@ -23,9 +23,9 @@ namespace Discord.Commands.Attributes.Preconditions | |||||
| GuildPermission = null; | 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) | if (!result.IsSuccess) | ||||
| return result; | return result; | ||||
| @@ -23,9 +23,9 @@ namespace Discord.Commands | |||||
| Comparer = comparer; | 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) | if (!result.IsSuccess) | ||||
| return result; | return result; | ||||
| @@ -46,14 +46,14 @@ namespace Discord.Commands | |||||
| { | { | ||||
| foreach (PreconditionAttribute precondition in Module.Preconditions) | 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) | if (!result.IsSuccess) | ||||
| return result; | return result; | ||||
| } | } | ||||
| foreach (PreconditionAttribute precondition in Preconditions) | 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) | if (!result.IsSuccess) | ||||
| return result; | return result; | ||||
| } | } | ||||