@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
78 lines • 2.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Select = void 0;
const eris_1 = require("eris");
const BaseComponent_1 = require("./BaseComponent");
const { ComponentTypes } = eris_1.Constants;
class Select extends BaseComponent_1.BaseComponent {
constructor(ctx, customId, handler) {
super(ctx, customId, handler);
this.maxOptions = 25;
this.definition.type = ComponentTypes.SELECT_MENU;
this.definition.options = [];
}
clearOptions() {
this.definition.options = [];
return this;
}
setOptions(options) {
if (options.length > this.maxOptions)
throw new Error(`setOptions: Cannot have more then ${this.maxOptions} options`);
// truncate option label if longer then 100 characters
for (const option of options) {
if (option.label.length > 100)
option.label = option.label.slice(0, 100);
if ((option.description?.length ?? 0) > 100)
option.description = option.description.slice(0, 100);
}
this.definition.options = options;
return this;
}
async setOptionsTranslated(options) {
const transform = [];
for (const option of options) {
let label = option.label;
if (typeof label === 'object')
label = await this.ctx.formatTranslation(label);
let description = option.description;
if (typeof description === 'object')
description = await this.ctx.formatTranslation(description);
transform.push({ ...option, label, description });
}
return this.setOptions(transform);
}
addOptions(options) {
const existing = this.definition.options.length;
if (existing + options.length > this.maxOptions)
throw new Error(`Cannot have more then ${this.maxOptions} options`);
// truncate option label if longer then 100 characters
for (const option of options) {
if (option.label.length > 100)
option.label = option.label.slice(0, 100);
if ((option.description?.length ?? 0) > 100)
option.description = option.description.slice(0, 100);
}
this.definition.options = [...this.definition.options, ...options];
return this;
}
addOption(option) {
return this.addOptions([option]);
}
placeholder(placeholder) {
this.definition.placeholder = placeholder;
return this;
}
async placeholderTranslated(key, repl, backup) {
return this.placeholder(await this.ctx.formatTranslation(key, repl, backup));
}
min(min) {
this.definition.min_values = min;
return this;
}
max(max) {
this.definition.max_values = max;
return this;
}
}
exports.Select = Select;
//# sourceMappingURL=Select.js.map