UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

65 lines (64 loc) 2.31 kB
/*! * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { ApplicationCommandType } from "discord-api-types/v10"; import { RexAutoCompleteInteraction } from "../interactions/slashCommands/autocomplete.js"; import { RexSlashCommandInteraction } from "../interactions/slashCommands/slashCommand.js"; import { RexSlashCommand } from "./command.js"; export class RexSlashHelpCommand extends RexSlashCommand { setExecute(fun) { this._execute = true; this.executeHelp = fun; return this; } setAutoCompleteFun(fun) { this.autocompleteHelp = fun; return this; } getCommand(commands) { const chatInput = new Map(); const user = new Map(); const message = new Map(); for (const cmd of commands.values()) { switch (cmd.commandInfo.type) { case ApplicationCommandType.ChatInput: case -2: case -1: { chatInput.set(cmd.commandInfo.name, cmd.commandInfo); break; } case ApplicationCommandType.Message: { message.set(cmd.name, cmd.commandInfo); break; } case ApplicationCommandType.User: { user.set(cmd.name, cmd.commandInfo); break; } } } return { chatInput, user, message, }; } run(int, commands) { if (this.executeHelp) { return this.executeHelp.apply(this.commandInfo, [ new RexSlashCommandInteraction(int, { autoDefer: this.autoDefer, debounceDelay: this.debounceDelay, deferEphemeral: this.deferEphemeral, useFailOver: this.useFailover }), this.getCommand(commands), ]); } } runAutoComplete(auto, commands) { if (this.autocompleteHelp) { return this.autocompleteHelp.apply(null, [new RexAutoCompleteInteraction(auto), this.getCommand(commands)]); } } setDefaultMemberPermissions() { return this; } }