blob: 3a72876a841efcb5ba0171a3bfb14665376e3653 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001export const event = "messageDelete";
pineafan32767212022-03-14 21:27:39 +00002
3export async function callback(client, message) {
pineafane625d782022-05-09 18:04:32 +01004 try {
pineafane23c4ec2022-07-27 21:56:27 +01005 if (message.author.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +01006 if (client.noLog.includes(`${message.guild.id}/${message.channel.id}/${message.id}`)) return;
7 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } =
8 message.channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
Skyler Grey11236ba2022-08-08 21:13:33 +010010 const audit = auditLog.entries.filter((entry) => entry.target.id === message.author.id).first();
pineafane625d782022-05-09 18:04:32 +010011 if (audit) {
12 if (audit.createdAt - 100 < new Date().getTime()) return;
pineafan32767212022-03-14 21:27:39 +000013 }
pineafan63fc5e22022-08-04 22:04:10 +010014 message.reference = message.reference || {};
15 let content = message.cleanContent;
16 content.replace("`", "\\`");
17 if (content.length > 256) content = content.substring(0, 253) + "...";
Skyler Grey75ea9172022-08-06 10:22:23 +010018 const attachments =
19 message.attachments.size +
20 (
21 message.content.match(
22 /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
23 ) ?? []
24 ).length;
pineafan63fc5e22022-08-04 22:04:10 +010025 let attachmentJump = "";
Skyler Grey11236ba2022-08-08 21:13:33 +010026 const config = (await client.database.guilds.read(message.guild.id)).logging.attachments.saved[
27 message.channel.id + message.id
28 ];
Skyler Grey75ea9172022-08-06 10:22:23 +010029 if (config) {
30 attachmentJump = ` [[View attachments]](${config})`;
31 }
pineafan63fc5e22022-08-04 22:04:10 +010032 const data = {
pineafane625d782022-05-09 18:04:32 +010033 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010034 type: "messageDelete",
35 displayName: "Message Deleted",
36 calculateType: "messageDelete",
pineafane625d782022-05-09 18:04:32 +010037 color: NucleusColors.red,
pineafan63fc5e22022-08-04 22:04:10 +010038 emoji: "MESSAGE.DELETE",
pineafane625d782022-05-09 18:04:32 +010039 timestamp: new Date().getTime()
40 },
41 separate: {
Skyler Grey11236ba2022-08-08 21:13:33 +010042 start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
pineafane625d782022-05-09 18:04:32 +010043 },
44 list: {
pineafanda6e5342022-07-03 10:03:16 +010045 messageId: entry(message.id, `\`${message.id}\``),
pineafane625d782022-05-09 18:04:32 +010046 sentBy: entry(message.author.id, renderUser(message.author)),
Skyler Grey11236ba2022-08-08 21:13:33 +010047 sentIn: entry(message.channel.id, renderChannel(message.channel)),
48 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafane625d782022-05-09 18:04:32 +010049 mentions: message.mentions.users.size,
pineafan02ba0232022-07-24 22:16:15 +010050 attachments: entry(attachments, attachments + attachmentJump),
pineafane625d782022-05-09 18:04:32 +010051 repliedTo: entry(
52 message.reference.messageId || null,
Skyler Grey75ea9172022-08-06 10:22:23 +010053 message.reference.messageId
54 ? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})`
55 : "None"
pineafane625d782022-05-09 18:04:32 +010056 )
57 },
58 hidden: {
59 guild: message.channel.guild.id
60 }
pineafan63fc5e22022-08-04 22:04:10 +010061 };
pineafan4edb7762022-06-26 19:21:04 +010062 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010063 } catch (e) {
64 console.log(e);
65 }
pineafan32767212022-03-14 21:27:39 +000066}