seyfert
Version:
The most advanced framework for discord bots
110 lines (109 loc) • 3.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RadioGroupOption = exports.RadioGroup = void 0;
const common_1 = require("../common");
const types_1 = require("../types");
const Base_1 = require("./Base");
class RadioGroup extends Base_1.BaseComponentBuilder {
#options = [];
constructor(data = {}) {
super({ type: types_1.ComponentType.RadioGroup, ...data });
}
/**
* Sets the ID for the radio group.
* @param id - The ID for the radio group.
* @returns The current RadioGroup instance.
*/
setId(id) {
this.data.id = id;
return this;
}
/**
* Sets the custom ID for the radio group.
* @param customId - The custom ID for the radio group.
* @returns The current RadioGroup instance.
*/
setCustomId(customId) {
this.data.custom_id = customId;
return this;
}
setOptions(options) {
this.#options = options.flat();
return this;
}
addOptions(...options) {
this.#options = this.#options.concat(options.flat());
return this;
}
/**
* Sets whether the radio group is required.
* @param required - Whether the radio group is required (true by discord side).
* @returns The current RadioGroup instance.
*/
setRequired(required) {
this.data.required = required;
return this;
}
toJSON() {
const options = [...this.#options.map(option => option.data), ...(this.data.options ?? [])];
const optionCount = options.length;
if (optionCount < 2 || optionCount > 10) {
throw new common_1.SeyfertError('INVALID_OPTIONS_LENGTH', {
metadata: {
...(0, common_1.createValidationMetadata)('number of options between 2 and 10', optionCount, {
component: 'RadioGroup',
}),
detail: 'RadioGroup must have between 2 and 10 options.',
},
});
}
return {
...this.data,
options,
};
}
}
exports.RadioGroup = RadioGroup;
class RadioGroupOption {
data;
constructor(data = {}) {
this.data = data;
}
/**
* Sets the label for the option.
* label - The label for the option.
* @returns The current RadioGroupOption instance.
*/
setLabel(label) {
this.data.label = label;
return this;
}
/**
* Sets the value for the option.
* value - The value for the option.
* @returns The current RadioGroupOption instance.
*/
setValue(value) {
this.data.value = value;
return this;
}
/**
* Sets the description for the option.
* description - The description for the option.
* @returns The current RadioGroupOption instance.
*/
setDescription(description) {
this.data.description = description;
return this;
}
/**
* Sets whether the option is the default.
* [value=true] - Indicates whether the option is the default (true by discord side).
* @returns The current RadioGroupOption instance.
*/
setDefault(value = true) {
this.data.default = value;
return this;
}
}
exports.RadioGroupOption = RadioGroupOption;