/** * @copyright NHCarrigan * @license Naomi's Public License * @author Teklu Abayneh */ import { DiscordAPIError, MessageFlags, type MessageContextMenuCommandInteraction, } from "discord.js"; import { ids } from "../config/ids.js"; import { getComponentsForNaomi } from "../utils/getComponentsForNaomi.js"; import { logger } from "../utils/logger.js"; /** * Forwards a message to Naomi via DM using a context menu command. * @param interaction -- The message context menu interaction. */ const forwardToOwner = async( interaction: MessageContextMenuCommandInteraction, ): Promise => { await interaction.deferReply({ flags: [ MessageFlags.Ephemeral ] }); if (interaction.user.id !== ids.users.naomi) { await interaction.editReply("❌ Only Naomi can use this command."); return; } const message = interaction.targetMessage; if (message.author.id === ids.users.naomi) { await interaction.editReply( "No need to forward your own message to yourself 😄", ); return; } try { const naomi = await interaction.client.users.fetch(ids.users.naomi); await naomi.send({ components: getComponentsForNaomi( message.author, message.content, message.url, ), flags: [ MessageFlags.IsComponentsV2 ], }); await logger.metric("forwarded_message", 1, { user: message.author.id }); await interaction.editReply({ content: "✅ Forwarded to your DMs!" }); } catch (error) { let replyText = "❌ Failed to forward message."; if (error instanceof DiscordAPIError && error.code === 50_007) { replyText = `${replyText} (Naomi's DMs might be closed)`; } if (error instanceof Error) { await logger.error("forwardToOwner command", error); } await interaction.editReply(replyText); } }; export { forwardToOwner };