sheweny
Version:
The powerful framework for create discord bots
74 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const BaseStructure_js_1 = require("./BaseStructure.js");
const index_js_1 = require("../helpers/index.js");
/**
* Represents an Button structure
* @extends {BaseStructure}
*/
class Button extends BaseStructure_js_1.BaseStructure {
/**
* Constructor for build a Button
* @param {ShewenyClient} [client] Client framework
* @param {CustomId} [customId] Custom id for one or more buttons
* @param {ButtonData | undefined} [options] The options of the button
*/
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 buttons
* @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 button in collections
* @returns {Collection<CustomId, Button>}
*/
async register() {
if (!this.path)
return new index_js_1.ShewenyError(this.client, 'PATH_NOT_DEFINE', 'Button', this.customId.toString());
const ButtonImported = (await Promise.resolve().then(() => __importStar(require(this.path)))).default;
const btn = new ButtonImported(this.client);
return btn;
}
/**
* Reload a button
* @returns {Promise<Collection<CustomId, Button> | ShewenyError>}
*/
async reload() {
this.unregister();
return this.register();
}
/**
* Unregister a button from collections
* @returns {boolean}
*/
unregister() {
this.client.collections.buttons?.delete(this.customId);
if (!this.path)
return false;
delete require.cache[require.resolve(this.path)];
return true;
}
}
exports.Button = Button;
//# sourceMappingURL=Button.js.map