@beni69/cmd
Version:
The command handler from my discord bot
37 lines • 1.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Command = void 0;
const ms_1 = __importDefault(require("ms"));
class Command {
/**
* Create a new command
* @param {CommandOptions} opts - Parameters for the command
* @param {CommandCallback} run - The actual function to run when the command is called
*/
constructor(opts, run) {
this.run = run;
this.opts = opts;
// if name is "name" convert it to "[name]"
if (typeof opts.names === "string")
this.opts.names = [opts.names];
this.opts.names = this.opts.names.map(str => str.toLowerCase());
if (opts.cooldown) {
const cd = (0, ms_1.default)(opts.cooldown.toString());
if (!cd)
throw new Error(`Cooldown for command ${this.opts.names[0]} is not in a valid format.`);
this.opts.cooldown = cd;
}
if (opts.globalCooldown) {
const cd = (0, ms_1.default)(opts.globalCooldown.toString());
if (!cd)
throw new Error(`Global cooldown for command ${this.opts.names[0]} is not in a valid format.`);
this.opts.globalCooldown = cd;
}
}
}
exports.Command = Command;
exports.default = Command;
//# sourceMappingURL=Command.js.map