UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

83 lines (82 loc) 3.14 kB
"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.RexSlashCommandOptionBase = void 0; const zod_1 = require("zod"); const locale_js_1 = require("../../helpers/locale.js"); const applicationCommandBase_js_1 = require("../../applicationCommandBase.js"); class RexSlashCommandOptionBase { constructor(_name, _description, type) { this._name = _name; this._description = _description; this.type = type; this._required = false; zod_1.z.string() .regex(/^[\w-]{1,32}$/g, `${_name} doesn't match ^[\w-]{1,32}$ regex`) .parse(this._name); } get name() { return this._name; } get description() { return this._description; } get required() { return this._required; } setRequired(req) { this._required = req; return this; } setNameLocalization(locale, localizedName) { if (localizedName) { applicationCommandBase_js_1.RexApplicationCommandBase.checkName(localizedName); } this._nameLocals ?? (this._nameLocals = new Map()); this._nameLocals.set((0, locale_js_1.getLocale)(locale), localizedName ?? undefined); return this; } setNameLocalizations(localizedNames) { const locals = (0, locale_js_1.parseLocalizations)(localizedNames, true); for (const [, desc] of locals) { if (desc) { applicationCommandBase_js_1.RexApplicationCommandBase.checkName(this.name); } } this._nameLocals = locals; return this; } setDescriptionLocalization(locale, localizedDescription) { if (localizedDescription) { applicationCommandBase_js_1.RexApplicationCommandBase.checkName(localizedDescription); } this._descriptionLocals ?? (this._descriptionLocals = new Map()); this._descriptionLocals.set((0, locale_js_1.getLocale)(locale), localizedDescription ?? undefined); return this; } setDescriptionsLocalizations(localizedDescriptions) { const locals = (0, locale_js_1.parseLocalizations)(localizedDescriptions, true); for (const [, desc] of locals) { if (desc) { applicationCommandBase_js_1.RexApplicationCommandBase.checkDescription(this.name, desc); } } this._descriptionLocals = locals; return this; } toJSON() { return { name: this._name, description: this._description, required: this._required, type: this.type, name_localizations: this._nameLocals ? Object.fromEntries(this._nameLocals) : undefined, description_localizations: this._descriptionLocals ? Object.fromEntries(this._descriptionLocals) : undefined, }; } } exports.RexSlashCommandOptionBase = RexSlashCommandOptionBase;