@guildedts/framework
Version:
A framework for creating a Guilded bot.
40 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Argument = void 0;
const guilded_ts_1 = require("guilded.ts");
/**
* Represents a command argument.
* @example
* class MyArgument extends Argument {
* name = 'my-argument';
* }
*/
class Argument {
command;
/** The description of the argument. */
description;
/** Whether the argument is required. */
required = true;
/** @param command The command the argument belongs to. */
constructor(command) {
this.command = command;
}
/** The usage of the argument. */
get usage() {
return this.required ? `<${this.name}>` : `[${this.name}]`;
}
/**
* Validates the argument.
* @param value The value of the argument.
* @returns The validated value, or error.
* @example argument.validate('hello'); // 'hello'
*/
async validate(value) {
if (!value && this.required)
throw new Error(`Missing required argument ${(0, guilded_ts_1.inlineCode)(this.name)}`);
else
return value;
}
}
exports.Argument = Argument;
//# sourceMappingURL=Argument.js.map