UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

136 lines (135 loc) 4.04 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.RexInteractionReply = exports.RexInteractionReplyBuilder = void 0; const v10_1 = require("discord-api-types/v10"); const discord_js_1 = require("discord.js"); class RexInteractionReplyBuilder { constructor() { this._flags = new Set(); } setEphemeral(value) { if (value) { this._flags.add("Ephemeral"); } else { this._flags.delete("Ephemeral"); } this.flags = 0; for (const flag of this._flags) { this.flags |= v10_1.MessageFlags[flag]; } return this; } setFetchReply(value) { this.fetchReply = value; return this; } setTTS(value) { this.tts = value; return this; } setContent(value) { this.content = value; return this; } setNonce(value) { this.nonce = value; return this; } addEmbeds(...embeds) { this.embeds ?? (this.embeds = []); this.embeds.push(...embeds.flat()); return this; } setEmbeds(...embeds) { this.embeds = embeds.flat(); return this; } setAllowedMentions(value) { this.allowedMentions = value; return this; } addComponents(...components) { this.components ?? (this.components = []); this.components.push(...components.flat()); return this; } setComponents(...components) { this.components = components.flat(); return this; } addActionRow(...components) { this.components ?? (this.components = []); const row = new discord_js_1.ActionRowBuilder({ type: v10_1.ComponentType.ActionRow }).setComponents(...components.flat()); this.components.push(row); return this; } addFiles(...files) { this.files ?? (this.files = []); this.files.push(...files.flat()); return this; } setFiles(...files) { this.files = files.flat(); return this; } setSurpressEmbeds(value) { if (value) { this._flags.add("SuppressEmbeds"); } else { this._flags.delete("SuppressEmbeds"); } this.flags = 0; for (const flag of this._flags) { this.flags += v10_1.MessageFlags[flag]; } return this; } toJSON() { return { fetchReply: this.fetchReply, content: this.content, embeds: this.embeds, files: this.files, components: this.components?.map(com => { if ((0, discord_js_1.isJSONEncodable)(com)) { return com.toJSON(); } return { type: v10_1.ComponentType.ActionRow, components: com.components.map(c => { if ((0, discord_js_1.isJSONEncodable)(c)) { return c.toJSON(); } return c; }), }; }), allowedMentions: this.allowedMentions, flags: this.flags, tts: this.tts, }; } toUpdateOptions() { return { ...this.toJSON(), flags: this._flags.has("SuppressEmbeds") ? v10_1.MessageFlags.SuppressEmbeds : undefined, }; } toMessage() { return { ...this.toJSON(), flags: this._flags.has("SuppressEmbeds") ? v10_1.MessageFlags.SuppressEmbeds : undefined, }; } } exports.RexInteractionReplyBuilder = RexInteractionReplyBuilder; class RexInteractionReply extends RexInteractionReplyBuilder { } exports.RexInteractionReply = RexInteractionReply;