From de618c4488b283dce32450e735a0ead8e4845b29 Mon Sep 17 00:00:00 2001 From: pineafan Date: Tue, 28 Feb 2023 18:03:18 +0000 Subject: [PATCH] Should work, don't have mongo configured --- src/commands/mod/purge.ts | 83 ++++++--------------------------- src/context/messages/purgeto.ts | 62 ++++++------------------ 2 files changed, 27 insertions(+), 118 deletions(-) diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts index 5e0a795..37b703e 100644 --- a/src/commands/mod/purge.ts +++ b/src/commands/mod/purge.ts @@ -1,4 +1,4 @@ -import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel, ButtonStyle, ButtonBuilder } from "discord.js"; +import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel, ButtonStyle, ButtonBuilder, Message } from "discord.js"; import type { SlashCommandSubcommandBuilder } from "discord.js"; import confirmationMessage from "../../utils/confirmationMessage.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; @@ -309,35 +309,17 @@ const callback = async (interaction: CommandInteraction): Promise => { } }; log(data); - let out = ""; // TODO: messageException throughout this file - messages.reverse().forEach((message) => { - if (!message) { - out += "Unknown message\n\n" - } else { - const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" }; - out += `${author.username}#${author.discriminator} (${author.id}) [${new Date( - message.createdTimestamp - ).toISOString()}]\n`; - if (message.content) { - const lines = message.content.split("\n"); - lines.forEach((line) => { - out += `> ${line}\n`; - }); - } - if (message.attachments.size > 0) { - message.attachments.forEach((attachment) => { - out += `Attachment > ${attachment.url}\n`; - }); - } - out += "\n\n"; - } - }); - const attachmentObject = { - attachment: Buffer.from(out), - name: `purge-${channel.id}-${Date.now()}.txt`, - description: "Purge log" - }; - const m = (await interaction.editReply({ + const messageArray: Message[] = messages.filter(message => !( + message!.components.some( + component => component.components.some( + child => child.customId?.includes("transcript") ?? false + ) + ) + )).map(message => message as Message); + const newOut = await client.database.transcripts.createTranscript(messageArray, interaction, interaction.member as GuildMember); + + const code = await client.database.transcripts.create(newOut); + await interaction.editReply({ embeds: [ new EmojiEmbed() .setEmoji("CHANNEL.PURGE.GREEN") @@ -347,47 +329,10 @@ const callback = async (interaction: CommandInteraction): Promise => { ], components: [ new Discord.ActionRowBuilder().addComponents([ - new Discord.ButtonBuilder() - .setCustomId("download") - .setLabel("Download transcript") - .setStyle(ButtonStyle.Success) - .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id")) + new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript?code=${code}`), ]) ] - })) as Discord.Message; - let component; - try { - component = await m.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.id === m.id, - time: 300000 - }); - } catch { - return; - } - if (component.customId === "download") { - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setEmoji("CHANNEL.PURGE.GREEN") - .setTitle("Purge") - .setDescription("Transcript uploaded above") - .setStatus("Success") - ], - components: [], - files: [attachmentObject] - }); - } else { - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setEmoji("CHANNEL.PURGE.GREEN") - .setTitle("Purge") - .setDescription("Messages cleared") - .setStatus("Success") - ], - components: [] - }); - } + }); } }; diff --git a/src/context/messages/purgeto.ts b/src/context/messages/purgeto.ts index 02d5d2a..aef159b 100644 --- a/src/context/messages/purgeto.ts +++ b/src/context/messages/purgeto.ts @@ -1,10 +1,8 @@ import confirmationMessage from '../../utils/confirmationMessage.js'; import EmojiEmbed from '../../utils/generateEmojiEmbed.js'; import { LoadingEmbed } from '../../utils/defaults.js'; -import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildTextBasedChannel, Message, MessageContextMenuCommandInteraction } from "discord.js"; +import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildMember, GuildTextBasedChannel, Message, MessageContextMenuCommandInteraction } from "discord.js"; import client from "../../utils/client.js"; -import getEmojiByName from '../../utils/getEmojiByName.js'; -import { JSONTranscriptFromMessageArray, JSONTranscriptToHumanReadable } from "../../utils/logTranscripts.js"; import { messageException } from '../../utils/createTemporaryStorage.js'; const command = new ContextMenuCommandBuilder() @@ -187,13 +185,16 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => { log(data); const messages: Message[] = deleted.map(m => m).filter(m => m instanceof Message).map(m => m as Message); if (messages.length === 1) messageException(interaction.guild!.id, interaction.channel.id, messages[0]!.id) - const transcript = JSONTranscriptToHumanReadable(JSONTranscriptFromMessageArray(messages)!); - const attachmentObject = { - attachment: Buffer.from(transcript), - name: `purge-${channel.id}-${Date.now()}.txt`, - description: "Purge log" - }; - const m = (await interaction.editReply({ + const messageArray: Message[] = messages.filter(message => !( + message!.components.some( + component => component.components.some( + child => child.customId?.includes("transcript") ?? false + ) + ) + )).map(message => message as Message); + const transcript = await client.database.transcripts.createTranscript(messageArray, interaction, interaction.member as GuildMember); + const code = await client.database.transcripts.create(transcript); + await interaction.editReply({ embeds: [ new EmojiEmbed() .setEmoji("CHANNEL.PURGE.GREEN") @@ -203,47 +204,10 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => { ], components: [ new Discord.ActionRowBuilder().addComponents([ - new Discord.ButtonBuilder() - .setCustomId("download") - .setLabel("Download transcript") - .setStyle(ButtonStyle.Success) - .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id")) + new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript?code=${code}`), ]) ] - })) as Discord.Message; - let component; - try { - component = await m.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.id === m.id, - time: 300000 - }); - } catch { - return; - } - if (component.customId === "download") { - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setEmoji("CHANNEL.PURGE.GREEN") - .setTitle("Purge") - .setDescription("Transcript uploaded above") - .setStatus("Success") - ], - components: [], - files: [attachmentObject] - }); - } else { - interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setEmoji("CHANNEL.PURGE.GREEN") - .setTitle("Purge") - .setDescription("Messages cleared") - .setStatus("Success") - ], - components: [] - }); - } + }); } const check = async (_interaction: MessageContextMenuCommandInteraction) => {