Skip to content

Commit

Permalink
Change messageDeleteBulk from custom to html!
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jul 17, 2024
1 parent 8604c98 commit 70a8148
Showing 1 changed file with 3 additions and 53 deletions.
56 changes: 3 additions & 53 deletions events/Message/messageDeleteBulk.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EmbedBuilder, AttachmentBuilder } from 'discord.js';
import { Buffer } from 'node:buffer';
import { generateFromMessages } from 'discord-html-transcripts';
import { EmbedBuilder } from 'discord.js';
import { QuickDB } from 'quick.db';
const db = new QuickDB();

Expand All @@ -16,57 +16,7 @@ export async function run(client, messages) {
const noLogChans = (await db.get(`servers.${server.id}.logs.noLogChans`)) || [];
if (noLogChans.includes(channel.id)) return;

const output = [];
const messagesArray = Array.from(messages.values());

messagesArray.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));

messagesArray.forEach((message) => {
const date = new Date(message.createdAt);

const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

const formattedDate = `[${days[date.getUTCDay()]} ${months[date.getUTCMonth()]} ${date.getUTCDate()} ${String(
date.getUTCHours(),
).padStart(2, '0')}:${String(date.getUTCMinutes()).padStart(2, '0')}:${String(date.getUTCSeconds()).padStart(
2,
'0',
)} ${date.getUTCFullYear()}]`;

const formattedAuthor = `(${message.author.tag} - ${message.author.id})`;
const formattedID = `[${message.id}]`;
output.push(`${formattedDate} ${formattedAuthor} ${formattedID}: `);

if (message.content) output.push(message.content + '\n');
if (message.embeds?.length > 0) {
const embeds = message.embeds;
const embedsOutput = [];
embedsOutput.push('Embeds: ');

embeds.forEach((em) => {
const jsonString = JSON.stringify(em.toJSON(), null, 2);
embedsOutput.push(jsonString);
});
output.push(embedsOutput.join('\n') + '\n');
}
if (message.attachments?.size > 0) {
const attachmentString = message.attachments.map((attachment) => `[${attachment.name}](${attachment.url})\n`);
output.push(attachmentString.join(''));
}
if (message.stickers?.size > 0) {
const stickerString = message.stickers.map((sticker) => `[${sticker.name}](${sticker.url})\n`);
output.push(stickerString.join(''));
}
output.push('\n');
});
const text = output.join('');

const attachment = new AttachmentBuilder(Buffer.from(text), {
name: 'deleted_messages.txt',
description: `Messages deleted from ${channel.name}`,
});

const attachment = await generateFromMessages(messages, channel);
const embed = new EmbedBuilder()
.setTitle('Bulk Messages Deleted')
.setColor('#FF0000')
Expand Down

0 comments on commit 70a8148

Please sign in to comment.