UNPKG

@notoiro/djs-button-pages

Version:

A simple yet powerful module for implementing customizable embed pages with buttons in Discord chat. Works only with Discord.js.

97 lines (96 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const discord_js_1 = require("discord.js"); /** * Class that wraps button's functionality. */ class ButtonWrapper { _data; _action; _switch; /** * Class that wraps button's functionality. * @param {Partila<ButtonData> | ButtonWrapper} data Either an interface for button styling or the class to be built from. */ constructor(data) { if (data) this.setData(data); } ; /** * @returns {Partial<ButtonData>} Button's styling. */ get data() { return this._data; } ; /** * @returns {ButtonACtion} Action that is called after the button is pressed. */ get action() { return this._action; } ; /** * @returns {ButtonSwitch} Action that is called to switch button's state. */ get switch() { return this._switch; } ; /** * @returns {ButtonBuilder} Ready button builder. */ get builtComponent() { return new discord_js_1.ButtonBuilder(this.toJSON()); } ; /** * Sets buttons data. * @param {Partial<ButtonData> | ButtonWrapper} data Either an interface for button styling or the class to be built from. * @returns {this} */ setData(data) { if (data instanceof ButtonWrapper) { this._data = data.data; this._action = data.action; this._switch = data.switch; } else { this._data = data; } ; return this; } ; /** * Sets action that is called after the button is pressed. * @param {ButtonAction} action Action that is called after the button is pressed. * @returns {this} */ setAction(action) { this._action = action; return this; } ; /** * Sets action that is called to switch button's state. * @param switchFunction Action that is called to switch button's state. * @returns {this} */ setSwitch(switchFunction) { this._switch = switchFunction; return this; } ; /** * Converts button styling to JSON-like object. * @returns {ButtonData} JSON-like object. */ toJSON() { return this._data; } ; } exports.default = ButtonWrapper; ;