UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

95 lines (94 loc) 3.02 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 { isJSONEncodable, StringSelectMenuBuilder } from "discord.js"; import { RexStringSelectMenuInteraction } from "../interactions/components/stringSelectMenu.js"; import { checkCustomId } from "../multiUse/component.js"; export class RexStringSelectMenuComponent extends StringSelectMenuBuilder { constructor(data) { if (typeof data == "string") { data = { custom_id: data, }; } checkCustomId(data.customId ?? data.custom_id); super(data); this.deferEphemeral = false; } get customId() { return this.data.custom_id; } toJSON() { return super.toJSON(); } setExecute(fun) { this.execute = fun; return this; } setAutoDefer(defer, ephemeral = false) { this.autoDefer = defer; this.deferEphemeral = ephemeral; return this; } setDebounceDelay(delay) { this.debounceDelay = delay; return this; } setAuditDelay(delay) { this.auditDelay = delay; return this; } setUseFailOver(value) { this.useFailover = value; return this; } run(inter) { if (this.execute) { return this.execute.apply(null, [ new RexStringSelectMenuInteraction(inter, { autoDefer: this.autoDefer, deferEphemeral: this.deferEphemeral, debounceDelay: this.debounceDelay, auditDelay: this.auditDelay, useFailOver: this.useFailover, }), ]); } } addOptionsNormalized(...options) { return this.addOptions(options.flat().map(opt => { return { label: opt.toString(), value: opt.toString() }; })); } setOptionsNormalized(...options) { return this.setOptions(options.flat().map(opt => { return { label: opt.toString(), value: opt.toString() }; })); } copy() { const menu = new RexStringSelectMenuComponent(this.toJSON()).setExecute(this.execute); if (this.debounceDelay) { menu.setDebounceDelay(this.debounceDelay); } if (this.auditDelay) { menu.setAuditDelay(this.auditDelay); } if (this.autoDefer) { menu.setAutoDefer(this.autoDefer, this.deferEphemeral); } if (this.useFailover) { menu.setUseFailOver(this.useFailover); } return menu; } static from(other) { if (isJSONEncodable(other)) { return new RexStringSelectMenuComponent(other.toJSON()); } return new RexStringSelectMenuComponent(other); } } export class RexSelectMenuComponent extends RexStringSelectMenuComponent { }