UNPKG

cumsystem

Version:

simple command system and command handler

94 lines (93 loc) 4.58 kB
"use strict"; 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 CommandSystem = __importStar(require("./index")); function grammar(str) { var newstring = str.slice(1, str.length); return str[0].toUpperCase() + newstring; } function addCommands(cs) { cs.addCommand(new CommandSystem.SimpleCommand('help', function (message) { var params = message.content.split(' '); if (params[1]) { var command_1; cs.commands.forEach(function (cmd) { if (command_1) { return; } if (cmd.name === params[1] || cmd.aliases.includes(params[1])) { command_1 = cmd; } }); // hey TS MAYBE IF YOU READ THE BEFORE CODE YOU WOULD KNOW IT WOULD BE ASSIGNED OR NOT AND IT CHECKS HERE IF IT IS ????? // @ts-ignore if (command_1) { var embed = new Discord.MessageEmbed() .setTitle("**" + grammar(command_1.name) + "** (" + grammar(command_1.category) + ")") .addField('Usage', cs.prefix + command_1.name + ' ' + command_1.displayUsage) .setDescription(command_1.description) .setColor(Math.floor(Math.random() * 16777215)); var commandExamplesPatched = command_1.examples.map(function (v) { return cs.prefix + command_1.name + ' ' + v; }); if (command_1.examples.length !== 0) { embed = embed.addField('Examples', '`' + commandExamplesPatched.join('`,\n`') + '`'); } if (command_1.aliases.length !== 0) { embed = embed.addField('Aliases', '`' + command_1.aliases.join('`, `') + '`'); } return { embed: embed }; } else { var categoryCommands = cs.commands.filter(function (c) { return c.category === params[1].toLowerCase(); }); if (categoryCommands.length === 0) return "Command or category `" + params[1] + "` not found!"; var embed = new Discord.MessageEmbed() .setTitle("**" + grammar(params[1].toLowerCase()) + "** [" + categoryCommands.length + "]") .setColor(Math.floor(Math.random() * 16777215)); embed.addField('Commands', categoryCommands.map(function (c) { return c.name; }).join('\n')); return { embed: embed }; } } else { var embed_1 = new Discord.MessageEmbed() .setTitle('**All Commands**') .setColor(Math.floor(Math.random() * 16777215)) .setFooter('Do help (category) to get all commands for a category!'); var categorizedCommands_1 = {}; cs.commands.forEach(function (command) { if (!command.hidden) { if (!categorizedCommands_1[command.category]) categorizedCommands_1[command.category] = []; categorizedCommands_1[command.category].push(command); } }); Object.keys(categorizedCommands_1).forEach(function (cat) { var commands = categorizedCommands_1[cat]; if (commands.length !== 0) embed_1.addField(grammar(cat) + " [" + commands.length + "]", "`" + commands.map(function (c) { return c.name.toLowerCase(); }).join('`, `') + "`"); }); return { embed: embed_1 }; } }) .setCategory('core') .setUsage('[string]') .setIgnorePrefix() .addAlias('cmds') .addClientPermission('EMBED_LINKS') .setDescription('see commands, or check out a comnmand in detail')); cs.addCommand(new CommandSystem.Command('ping', function (message) { var dateStart = Date.now(); message.channel.send('hol up').then(function (m) { m.edit("Message latency: " + (Date.now() - dateStart) + "ms\nWebsocket ping: " + message.client.ws.ping + "ms"); }); }) .setCategory('core') .setDescription('ping the bot')); } exports.addCommands = addCommands;