detritus-client
Version:
A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.
82 lines (81 loc) • 2.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentButton = void 0;
const baseset_1 = require("../../collections/baseset");
const constants_1 = require("../../constants");
const emoji_1 = require("../../structures/emoji");
const utils_1 = require("../../utils");
const actionbase_1 = require("./actionbase");
const keysComponentButton = new baseset_1.BaseSet([
constants_1.DiscordKeys.CUSTOM_ID,
constants_1.DiscordKeys.DISABLED,
constants_1.DiscordKeys.EMOJI,
constants_1.DiscordKeys.LABEL,
constants_1.DiscordKeys.STYLE,
constants_1.DiscordKeys.TYPE,
constants_1.DiscordKeys.URL,
]);
/**
* Utils Component Button Structure
* @category Utils
*/
class ComponentButton extends actionbase_1.ComponentActionBase {
constructor(data = {}) {
super(data);
this._keys = keysComponentButton;
this.style = constants_1.MessageComponentButtonStyles.PRIMARY;
this.type = constants_1.MessageComponentTypes.BUTTON;
this.merge(data);
this.type = constants_1.MessageComponentTypes.BUTTON;
}
setCustomId(customId) {
this.merge({ [constants_1.DiscordKeys.CUSTOM_ID]: customId });
return this;
}
setDisabled(disabled) {
this.merge({ disabled });
return this;
}
setEmoji(emoji) {
this.merge({ emoji });
return this;
}
setLabel(label) {
this.merge({ label });
return this;
}
setStyle(style) {
this.merge({ style });
return this;
}
setUrl(url) {
this.merge({ url });
if (url) {
this.setStyle(constants_1.MessageComponentButtonStyles.LINK);
}
return this;
}
mergeValue(key, value) {
switch (key) {
case constants_1.DiscordKeys.EMOJI:
{
if (value instanceof emoji_1.Emoji) {
value = { animated: value.animated, id: value.id, name: value.name };
}
else if (typeof (value) === 'string') {
const { matches } = utils_1.regex(constants_1.DiscordRegexNames.EMOJI, value);
if (matches.length) {
value = matches[0];
}
else {
value = { name: value };
}
}
}
;
break;
}
return super.mergeValue(key, value);
}
}
exports.ComponentButton = ComponentButton;