diff --git a/src/commands/context-menu/deleteMsg.ts b/src/commands/context-menu/deleteMsg.ts index 04a28bed..1241d646 100644 --- a/src/commands/context-menu/deleteMsg.ts +++ b/src/commands/context-menu/deleteMsg.ts @@ -1,8 +1,13 @@ -import { ApplicationCommandType, CacheType, ContextMenuCommandInteraction, RESTPostAPIApplicationCommandsJSONBody } from 'discord.js'; +import { + ApplicationCommandType, + CacheType, + ContextMenuCommandInteraction, + RESTPostAPIApplicationCommandsJSONBody, +} from 'discord.js'; import BaseCommand from '../BaseCommand.js'; -import db from '../../utils/Db.js'; import { checkIfStaff } from '../../utils/Utils.js'; import { emojis } from '../../utils/Constants.js'; +import db from '../../utils/Db.js'; export default class DeleteMessage extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { @@ -19,16 +24,21 @@ export default class DeleteMessage extends BaseCommand { include: { hub: true }, }); - if (!messageInDb) return await interaction.editReply('Unknown Message. If it has been sent in the past minute, please wait few more seconds and try again.'); + if (!messageInDb) { + return await interaction.editReply( + 'Unknown Message. If it has been sent in the past minute, please wait few more seconds and try again.', + ); + } const interchatStaff = checkIfStaff(interaction.user.id); if ( !interchatStaff && !messageInDb.hub?.moderators.find((m) => m.userId === interaction.user.id) && - messageInDb.hub?.ownerId !== interaction.user.id && - interaction.user.id !== messageInDb.authorId - ) return await interaction.editReply(`${emojis.no} You are not the author of this message.`); - + messageInDb.hub?.ownerId !== interaction.user.id && + interaction.user.id !== messageInDb.authorId + ) { + return await interaction.editReply(`${emojis.no} You are not the author of this message.`); + } // find all the messages through the network const channelSettingsArr = await db.connectedList.findMany({ @@ -39,22 +49,28 @@ export default class DeleteMessage extends BaseCommand { if (!connection) return false; const webhookURL = connection.webhookURL.split('/'); - const webhook = await interaction.client.fetchWebhook(webhookURL[webhookURL.length - 2])?.catch(() => null); + const webhook = await interaction.client + .fetchWebhook(webhookURL[webhookURL.length - 2]) + ?.catch(() => null); if (webhook?.owner?.id !== interaction.client.user?.id) return false; // finally, delete the message - return await webhook?.deleteMessage(element.messageId, connection.parentId ? connection.channelId : undefined) + return await webhook + ?.deleteMessage(element.messageId, connection.parentId ? connection.channelId : undefined) .then(() => true) .catch(() => false); }); const resultsArray = await Promise.all(results); const deleted = resultsArray.reduce((acc, cur) => acc + (cur ? 1 : 0), 0); - await interaction.editReply(`${emojis.yes} Your message has been deleted from __**${deleted}/${resultsArray.length}**__ servers.`).catch(() => null); + await interaction + .editReply( + `${emojis.yes} Message by **<@${messageInDb.authorId}> (${messageInDb.authorId})** has been deleted from __**${deleted}/${resultsArray.length}**__ servers.`, + ) + .catch(() => null); // log the deleted message for moderation purposes TODO // if (interaction.inCachedGuild()) networkMessageDelete(interaction.member, interaction.targetMessage); } - -} \ No newline at end of file +}