UNPKG

sheweny

Version:

The powerful framework for create discord bots

74 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Modal = void 0; const BaseStructure_js_1 = require("./BaseStructure.js"); const index_js_1 = require("../helpers/index.js"); /** * Represents an Modal structure * @extends {BaseStructure} */ class Modal extends BaseStructure_js_1.BaseStructure { /** * Constructor to build a Modal * @param {ShewenyClient} [client] Client framework * @param {CustomId} [customId] Custom id for one or more modals * @param {ModalData | undefined} [options] The options of the modal */ constructor(client, customId, options) { super(client, options?.enabled); /** * Cooldown of a button in seconds * @type {number} */ Object.defineProperty(this, "cooldown", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * Custom id for one or more modals * @type {CustomId} */ Object.defineProperty(this, "customId", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.cooldown = (options?.cooldown || client.managers.buttons?.default?.cooldown) ?? 0; this.customId = customId; } /** * Register a modal in collections * @returns {Promise<Modal | ShewenyError>} */ async register() { if (!this.path) return new index_js_1.ShewenyError(this.client, 'PATH_NOT_DEFINE', 'Modal', this.customId.toString()); const ModalImported = (await Promise.resolve().then(() => __importStar(require(this.path)))).default; const mod = new ModalImported(this.client); return mod; } /** * Reload a modal * @returns {Promise<Modal> | ShewenyError>} */ async reload() { this.unregister(); return this.register(); } /** * Unregister a modal from collections * @returns {boolean} */ unregister() { this.client.collections.modals?.delete(this.customId); if (!this.path) return false; delete require.cache[require.resolve(this.path)]; return true; } } exports.Modal = Modal; //# sourceMappingURL=Modal.js.map