UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

131 lines (130 loc) 3.74 kB
/*! * 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/. */ import { ComponentType, MessageFlags } from "discord-api-types/v10"; import { ActionRowBuilder, isJSONEncodable, } from "discord.js"; export 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 |= 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 ActionRowBuilder({ type: 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 += MessageFlags[flag]; } return this; } toJSON() { return { fetchReply: this.fetchReply, content: this.content, embeds: this.embeds, files: this.files, components: this.components?.map(com => { if (isJSONEncodable(com)) { return com.toJSON(); } return { type: ComponentType.ActionRow, components: com.components.map(c => { if (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") ? MessageFlags.SuppressEmbeds : undefined, }; } toMessage() { return { ...this.toJSON(), flags: this._flags.has("SuppressEmbeds") ? MessageFlags.SuppressEmbeds : undefined, }; } } export class RexInteractionReply extends RexInteractionReplyBuilder { }