blob: 4cdbdb26febf49b64f37218c61fb49ff7cc2df13 [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 Grey75ea9172022-08-06 10:22:23 +01006 if (
7 client.noLog.includes(
8 `${message.guild.id}/${message.channel.id}/${message.id}`
9 )
10 )
11 return;
12 const {
13 getAuditLog,
14 log,
15 NucleusColors,
16 entry,
17 renderUser,
18 renderDelta,
19 renderChannel
20 } = message.channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010021 const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
Skyler Grey75ea9172022-08-06 10:22:23 +010022 const audit = auditLog.entries
23 .filter((entry) => entry.target.id === message.author.id)
24 .first();
pineafane625d782022-05-09 18:04:32 +010025 if (audit) {
26 if (audit.createdAt - 100 < new Date().getTime()) return;
pineafan32767212022-03-14 21:27:39 +000027 }
pineafan63fc5e22022-08-04 22:04:10 +010028 message.reference = message.reference || {};
29 let content = message.cleanContent;
30 content.replace("`", "\\`");
31 if (content.length > 256) content = content.substring(0, 253) + "...";
Skyler Grey75ea9172022-08-06 10:22:23 +010032 const attachments =
33 message.attachments.size +
34 (
35 message.content.match(
36 /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
37 ) ?? []
38 ).length;
pineafan63fc5e22022-08-04 22:04:10 +010039 let attachmentJump = "";
Skyler Grey75ea9172022-08-06 10:22:23 +010040 const config = (await client.database.guilds.read(message.guild.id))
41 .logging.attachments.saved[message.channel.id + message.id];
42 if (config) {
43 attachmentJump = ` [[View attachments]](${config})`;
44 }
pineafan63fc5e22022-08-04 22:04:10 +010045 const data = {
pineafane625d782022-05-09 18:04:32 +010046 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010047 type: "messageDelete",
48 displayName: "Message Deleted",
49 calculateType: "messageDelete",
pineafane625d782022-05-09 18:04:32 +010050 color: NucleusColors.red,
pineafan63fc5e22022-08-04 22:04:10 +010051 emoji: "MESSAGE.DELETE",
pineafane625d782022-05-09 18:04:32 +010052 timestamp: new Date().getTime()
53 },
54 separate: {
Skyler Grey75ea9172022-08-06 10:22:23 +010055 start: content
56 ? `**Message:**\n\`\`\`${content}\`\`\``
57 : "**Message:** *Message had no content*"
pineafane625d782022-05-09 18:04:32 +010058 },
59 list: {
pineafanda6e5342022-07-03 10:03:16 +010060 messageId: entry(message.id, `\`${message.id}\``),
pineafane625d782022-05-09 18:04:32 +010061 sentBy: entry(message.author.id, renderUser(message.author)),
Skyler Grey75ea9172022-08-06 10:22:23 +010062 sentIn: entry(
63 message.channel.id,
64 renderChannel(message.channel)
65 ),
66 deleted: entry(
67 new Date().getTime(),
68 renderDelta(new Date().getTime())
69 ),
pineafane625d782022-05-09 18:04:32 +010070 mentions: message.mentions.users.size,
pineafan02ba0232022-07-24 22:16:15 +010071 attachments: entry(attachments, attachments + attachmentJump),
pineafane625d782022-05-09 18:04:32 +010072 repliedTo: entry(
73 message.reference.messageId || null,
Skyler Grey75ea9172022-08-06 10:22:23 +010074 message.reference.messageId
75 ? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})`
76 : "None"
pineafane625d782022-05-09 18:04:32 +010077 )
78 },
79 hidden: {
80 guild: message.channel.guild.id
81 }
pineafan63fc5e22022-08-04 22:04:10 +010082 };
pineafan4edb7762022-06-26 19:21:04 +010083 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010084 } catch (e) {
85 console.log(e);
86 }
pineafan32767212022-03-14 21:27:39 +000087}