UNPKG

@beni69/cmd

Version:

The command handler from my discord bot

60 lines 2.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.init = void 0; const discord_js_1 = require("discord.js"); const Command_1 = __importDefault(require("./Command")); function init(handler) { const settings = handler.getOpts.helpCommand; const command = new Command_1.default({ names: settings.names, description: "Display help" }, ({ trigger, client, handler, text, argv }) => { const embed = new discord_js_1.MessageEmbed() .setColor((settings === null || settings === void 0 ? void 0 : settings.color) || "RANDOM") .setTimestamp() .setFooter(trigger.author.tag, trigger.author.displayAvatarURL({ dynamic: true })); //* default help command if (!text) { embed.setTitle(settings.title || client.user.username); const commands = handler.getCommands; const categories = new Map(); // ignore the help command and test commands in non-test servers commands .filter(item => item.opts.names !== command.opts.names && (!item.opts.test || handler.getOpts.testServers.has(trigger.guild.id))) .forEach(item => { const c = categories.get(item.opts.category) || []; c === null || c === void 0 ? void 0 : c.push(item); categories.set(item.opts.category, c); }); categories.forEach(c => { const field = c.map(item => [ `**${capitalise(item.opts.names[0])}**`, item.opts.description, ] .join("\n") .trim()); embed.addField(`*${capitalise(c[0].opts.category)}*`, field.join("\n"), true); }); } //* help for a specific command else { const command = handler.getCommand(text); if (!command) return; embed .setTitle(command.opts.names[0]) .setDescription(command.opts.description || "This command doesn't have a description.") .addField("Category", command.opts.category, true); } trigger.channel.send({ embeds: [embed] }); function capitalise(str) { return str[0].toUpperCase() + str.substr(1); } }); handler.commands.set(command.opts.names[0], command); } exports.init = init; //# sourceMappingURL=HelpCommand.js.map