Source: Command.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Command = void 0;
const Utils_1 = require("./Utils");
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];
        if (opts.cooldown) {
            const cd = Utils_1.toMillisec(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 = Utils_1.toMillisec(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