@guildedts/framework
Version:
A framework for creating a Guilded bot.
45 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringArgument = void 0;
const guilded_ts_1 = require("guilded.ts");
const Argument_1 = require("./Argument");
/**
* Represents a string command argument.
* @example
* class MyArgument extends StringArgument {
* name = 'my-argument';
* }
*/
class StringArgument extends Argument_1.Argument {
/** The default value of the argument. */
default;
/** The choices of the argument. */
choices = [];
/** The max size of the argument. */
max;
/** The min size of the argument. */
min;
/**
* Validates the string argument.
* @param value The value of the argument.
* @returns The validated value, or error.
* @example stringArgument.validate('hello'); // 'hello'
*/
async validate(value) {
value = (await super.validate(value));
if (this.choices.length > 0 && !this.choices.includes(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 && value.length > this.max)
throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must be shorter than ${this.max} characters`);
else if (this.min && value.length < this.min)
throw new Error(`${(0, guilded_ts_1.inlineCode)(this.name)} must be longer than ${this.min} characters`);
else if (this.default && !value)
return this.default;
else
return value;
}
}
exports.StringArgument = StringArgument;
//# sourceMappingURL=StringArgument.js.map