UNPKG

cumsystem

Version:

simple command system and command handler

66 lines (65 loc) 2.56 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); var Discord = __importStar(require("discord.js")); var Command_1 = require("./Command"); Discord; // eslint ....... /** * A command the function of which returns the message to send back * @extends Command */ var SimpleCommand = /** @class */ (function (_super) { __extends(SimpleCommand, _super); /** * Create a command * @example * ```typescript * let command = new CommandSystem.SimpleCommand('test', () => { * return 'Testing!'; * }); * ``` * @param {string} name The name, also what invokes the command * @param {Function} cfunction The function to run after the command is ran, returns content that will be sent back to the user, or a promise that returns the content */ function SimpleCommand(name, cfunction) { var _this = _super.call(this, name, cfunction) || this; _this.cfunc = function (message, content) { var returned = cfunction(message, content); if (!returned) { process.emitWarning("Command output of " + name + " returned nothing, please use Command class instead"); return null; } if (returned.then) { // check if its a promise or not returned.then(function (messageResult) { return message.channel.send(messageResult); }); } else { return message.channel.send(returned); } return null; }; return _this; } return SimpleCommand; }(Command_1.Command)); exports.SimpleCommand = SimpleCommand;