@wilcosp/rex
Version:
Rex is an automated command manager for discord js
98 lines (97 loc) • 3.24 kB
JavaScript
"use strict";
/*!
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RexSlashCommandStringOption = void 0;
const v10_1 = require("discord-api-types/v10");
const optionsBase_js_1 = require("./optionsBase.js");
class RexSlashCommandStringOption extends optionsBase_js_1.RexSlashCommandOptionBase {
constructor(name, description) {
super(name, description, v10_1.ApplicationCommandOptionType.String);
}
get autocomplete() {
return this._autocomplete;
}
addChoice(name, value, name_localizations) {
this._choices ?? (this._choices = []);
this._choices.push({
name,
value,
name_localizations,
});
return this;
}
addChoices(...choices) {
this._choices ?? (this._choices = []);
this._choices.push(...choices.flat());
return this;
}
addChoicesNormalized(...values) {
this._choices ?? (this._choices = []);
this._choices.push(...values.flat().map(i => {
return {
value: i.toString(),
name: i.toString(),
};
}));
return this;
}
setChoices(...choices) {
this._choices = choices.flat();
return this;
}
setChoicesNormalized(...values) {
this._choices = values.flat().map(i => {
return {
value: i.toString(),
name: i.toString(),
};
});
return this;
}
setAutocomplete(value) {
this._autocomplete = value;
return this;
}
setMinLength(minLength) {
if (minLength < 0) {
throw TypeError("min length needs to be at least 0");
}
if (minLength > (this._maxLength ?? Number.MAX_SAFE_INTEGER)) {
throw TypeError("Min length needs to be smaller than max length");
}
this._minLength = minLength;
return this;
}
setMaxLength(maxLength) {
if (maxLength < 1) {
throw TypeError("max length needs to be at least 1");
}
if (maxLength < (this._minLength ?? 0)) {
throw TypeError("max length needs to be bigger the min length");
}
this._maxLength = maxLength;
return this;
}
setMinMaxLength(minLength, maxLength) {
if (minLength < 0) {
throw TypeError("min length needs to be at least 0");
}
if (maxLength < 1) {
throw TypeError("max length needs to be at least 1");
}
if (minLength > maxLength) {
throw TypeError("max length needs to be bigger the min length");
}
this._minLength = minLength;
this._maxLength = maxLength;
return this;
}
toJSON() {
return { ...super.toJSON(), choices: this._choices?.slice(0, 25), autocomplete: this._autocomplete, min_length: this._minLength, max_length: this._maxLength };
}
}
exports.RexSlashCommandStringOption = RexSlashCommandStringOption;