Should work, don't have mongo configured

pull/11/head
pineafan 3 years ago
parent 8f5cb24dc2
commit de618c4488
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -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 type { SlashCommandSubcommandBuilder } from "discord.js";
import confirmationMessage from "../../utils/confirmationMessage.js"; import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@ -309,35 +309,17 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
}; };
log(data); log(data);
let out = ""; // TODO: messageException throughout this file const messageArray: Message[] = messages.filter(message => !(
messages.reverse().forEach((message) => { message!.components.some(
if (!message) { component => component.components.some(
out += "Unknown message\n\n" child => child.customId?.includes("transcript") ?? false
} else { )
const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" }; )
out += `${author.username}#${author.discriminator} (${author.id}) [${new Date( )).map(message => message as Message);
message.createdTimestamp const newOut = await client.database.transcripts.createTranscript(messageArray, interaction, interaction.member as GuildMember);
).toISOString()}]\n`;
if (message.content) { const code = await client.database.transcripts.create(newOut);
const lines = message.content.split("\n"); await interaction.editReply({
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({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN") .setEmoji("CHANNEL.PURGE.GREEN")
@ -347,47 +329,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
], ],
components: [ components: [
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder() new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript?code=${code}`),
.setCustomId("download")
.setLabel("Download transcript")
.setStyle(ButtonStyle.Success)
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
]) ])
] ]
})) 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: []
});
}
} }
}; };

@ -1,10 +1,8 @@
import confirmationMessage from '../../utils/confirmationMessage.js'; import confirmationMessage from '../../utils/confirmationMessage.js';
import EmojiEmbed from '../../utils/generateEmojiEmbed.js'; import EmojiEmbed from '../../utils/generateEmojiEmbed.js';
import { LoadingEmbed } from '../../utils/defaults.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 client from "../../utils/client.js";
import getEmojiByName from '../../utils/getEmojiByName.js';
import { JSONTranscriptFromMessageArray, JSONTranscriptToHumanReadable } from "../../utils/logTranscripts.js";
import { messageException } from '../../utils/createTemporaryStorage.js'; import { messageException } from '../../utils/createTemporaryStorage.js';
const command = new ContextMenuCommandBuilder() const command = new ContextMenuCommandBuilder()
@ -187,13 +185,16 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => {
log(data); log(data);
const messages: Message[] = deleted.map(m => m).filter(m => m instanceof Message).map(m => m as Message); 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) if (messages.length === 1) messageException(interaction.guild!.id, interaction.channel.id, messages[0]!.id)
const transcript = JSONTranscriptToHumanReadable(JSONTranscriptFromMessageArray(messages)!); const messageArray: Message[] = messages.filter(message => !(
const attachmentObject = { message!.components.some(
attachment: Buffer.from(transcript), component => component.components.some(
name: `purge-${channel.id}-${Date.now()}.txt`, child => child.customId?.includes("transcript") ?? false
description: "Purge log" )
}; )
const m = (await interaction.editReply({ )).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: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN") .setEmoji("CHANNEL.PURGE.GREEN")
@ -203,47 +204,10 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => {
], ],
components: [ components: [
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder() new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript?code=${code}`),
.setCustomId("download")
.setLabel("Download transcript")
.setStyle(ButtonStyle.Success)
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
]) ])
] ]
})) 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) => { const check = async (_interaction: MessageContextMenuCommandInteraction) => {

Loading…
Cancel
Save