import Command from '../structures/Command'; /** * ```js * validator.apply(cmd => cmd.message.author.id === 'some id', 'uh oh'); // executed at runtime * // or * validator.apply(cmd.message.author.id === 'some id', 'uh oh'); // executed immediately * ``` */ export declare type ValidationFunction = (v: Validator) => boolean; /** * Passed as a parameter to command validators. Arguments will not be available in this class, * as this is run before arguments are resolved from the command. Use for permissions checks and * other pre-command validations. * * ```js * // Using a custom validator. * class CustomValidator extends Validator { * ensureGuild() { * return this.apply(this.command.message.channel.type === 'text', 'Command must be run in a guild channel.'); * } * } * * // Usage in command * exports.validator = processor => { * return processor.ensureGuild(); * } * ``` * * ```js * // Usage without a custom validator * exports.validator = (processor, command) => { * return processor.apply(command.message.channel.type === 'text', 'Command must be run in a guild channel.'); * } * ``` */ export default class Validator { command: Command; /** * The reason this validator is invalid. */ reason: string | null; /** * Whether to automatically respond with reason when invalid. */ respond: boolean; /** * Whether this validator is valid. */ valid: boolean; /** * Functions to execute when determining validity. Maps validation functions to reasons. */ private exec; constructor(cmd: Command); /** * Test a new boolean for validity. * * ```js * const validator = new Validator(); * validator.apply(aCondition, 'borke') || validator.apply(otherCondition, 'different borke'); * yield validator; * ``` */ apply(test: ValidationFunction | boolean, reason?: string | null): this; then(resolver?: ((value: void) => TResult1 | PromiseLike), rejector?: ((value: Error) => TResult2 | PromiseLike)): Promise; }