Tickets! and a lot of bug fixes
diff --git a/src/context/messages/purgeto.ts b/src/context/messages/purgeto.ts
index e2ec6e4..df52e0b 100644
--- a/src/context/messages/purgeto.ts
+++ b/src/context/messages/purgeto.ts
@@ -1,9 +1,10 @@
import confirmationMessage from '../../utils/confirmationMessage.js';
import EmojiEmbed from '../../utils/generateEmojiEmbed.js';
-import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
+import { LoadingEmbed } from '../../utils/defaults.js';
import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildTextBasedChannel, MessageContextMenuCommandInteraction } from "discord.js";
import client from "../../utils/client.js";
import getEmojiByName from '../../utils/getEmojiByName.js';
+import { JSONTranscriptFromMessageArray, JSONTranscriptToHumanReadable } from "../../utils/logTranscripts.js";
const command = new ContextMenuCommandBuilder()
.setName("Purge up to here")
@@ -12,7 +13,7 @@
async function waitForButton(m: Discord.Message, member: Discord.GuildMember): Promise<boolean> {
let component;
try {
- component = m.awaitMessageComponent({ time: 200000, filter: (i) => i.user.id === member.id });
+ component = m.awaitMessageComponent({ time: 200000, filter: (i) => i.user.id === member.id && i.channel!.id === m.channel.id });
} catch (e) {
return false;
}
@@ -120,6 +121,7 @@
)
.setColor("Danger")
.addReasonButton(reason ?? "")
+ .setFailedMessage("No changes were made", "Success", "CHANNEL.PURGE.GREEN")
.send(true)
reason = reason ?? ""
if (confirmation.cancelled) timedOut = true;
@@ -130,16 +132,7 @@
deleteUser = confirmation.components["onlySelectedUser"]!.active;
}
} while (!chosen && !timedOut);
- if (timedOut) return;
- if (!confirmation.success) {
- await interaction.editReply({ embeds: [new EmojiEmbed()
- .setTitle("Purge")
- .setDescription("No changes were made")
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setStatus("Success")
- ], components: [] });
- return;
- }
+ if (timedOut || !confirmation.success) return;
const filteredMessages = history
.filter(m => m.createdTimestamp >= allowedMessage!.createdTimestamp) // older than selected
.filter(m => deleteUser ? m.author.id === targetMember.id : true) // only selected user
@@ -191,31 +184,9 @@
}
};
log(data);
- let out = "";
- deleted.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 transcript = JSONTranscriptToHumanReadable(JSONTranscriptFromMessageArray(deleted.map((m) => m as Discord.Message))!);
const attachmentObject = {
- attachment: Buffer.from(out),
+ attachment: Buffer.from(transcript),
name: `purge-${channel.id}-${Date.now()}.txt`,
description: "Purge log"
};
@@ -240,7 +211,7 @@
let component;
try {
component = await m.awaitMessageComponent({
- filter: (m) => m.user.id === interaction.user.id,
+ filter: (m) => m.user.id === interaction.user.id && m.channel!.id === interaction.channel!.id,
time: 300000
});
} catch {