UNPKG

@guildedts/framework

Version:

A framework for creating a Guilded bot.

47 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberArgument = void 0; const guilded_ts_1 = require("guilded.ts"); const Argument_1 = require("./Argument"); /** * Represents a number command argument. * @example * class MyArgument extends NumberArgument { * name = 'my-argument'; * } */ class NumberArgument extends Argument_1.Argument { /** The default value of the argument. */ default; /** The choices of the argument. */ choices = []; /** The max value of the argument. */ max; /** The min value of the argument. */ min; /** * Validates the number argument. * @param value The value of the argument. * @returns The validated value, or error. * @example numberArgument.validate('1'); // 1 */ async validate(value) { value = (await super.validate(value)); if (isNaN(value)) throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must be a number.`); else if (this.choices.length > 0 && !this.choices.includes(Number(value))) throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must tbe one of the following: ${this.choices .map((choice) => (0, guilded_ts_1.inlineCode)(`${choice}`)) .join(', ')}.`); else if (this.max && Number(value) > this.max) throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must be less than ${this.max}.`); else if (this.min && Number(value) < this.min) throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must be greater than ${this.min}.`); else if (this.default && !value) return this.default; else return Number(value); } } exports.NumberArgument = NumberArgument; //# sourceMappingURL=NumberArgument.js.map