blob: 9563a3378617959d35c079e227d425e14c5de548 [file] [log] [blame]
PineaFan752af462022-12-31 21:59:38 +00001import type { NucleusClient } from "../utils/client.js";
PineaFan538d3752023-01-12 21:48:23 +00002import Discord, { AuditLogEvent, GuildAuditLogsEntry, Message, User } from "discord.js";
pineafan0f5cc782022-08-12 21:55:42 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "messageDelete";
pineafan32767212022-03-14 21:27:39 +00005
PineaFan752af462022-12-31 21:59:38 +00006export async function callback(client: NucleusClient, message: Message) {
TheCodedProf4f79da12023-01-31 16:50:37 -05007 if (message.author.id === client.user!.id) return;
8 if (message.author.bot) return;
9 if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
10 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
11 const auditLog = (await getAuditLog(message.guild!, AuditLogEvent.MemberBanAdd))
12 .filter((entry: GuildAuditLogsEntry) => (entry.target! as User).id === message.author.id)[0];
13 if (auditLog) {
14 if (auditLog.createdTimestamp - 1000 < new Date().getTime()) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010015 }
TheCodedProf4f79da12023-01-31 16:50:37 -050016 const replyTo = message.reference;
17 let content = message.cleanContent;
18 content.replace("`", "\\`");
19 if (content.length > 256) content = content.substring(0, 253) + "...";
20 const attachments =
21 message.attachments.size + (
22 message.content.match(
23 /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
24 ) ?? []
25 ).length;
26 let attachmentJump = "";
27 const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
28 message.channel.id + message.id
29 ];
30 if (config) { attachmentJump = ` [[View attachments]](${config})`; }
31 const data = {
32 meta: {
33 type: "messageDelete",
34 displayName: "Message Deleted",
35 calculateType: "messageDelete",
36 color: NucleusColors.red,
37 emoji: "MESSAGE.DELETE",
38 timestamp: new Date().getTime()
39 },
40 separate: {
41 start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
42 },
43 list: {
44 messageId: entry(message.id, `\`${message.id}\``),
45 sentBy: entry(message.author.id, renderUser(message.author)),
46 sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)),
47 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
48 mentions: message.mentions.users.size,
49 attachments: entry(attachments, attachments + attachmentJump),
50 repliedTo: entry(
51 replyTo ? replyTo.messageId! : null,
52 replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
53 : "None"
54 )
55 },
56 hidden: {
57 guild: message.guild!.id
58 }
59 };
60 log(data);
pineafan32767212022-03-14 21:27:39 +000061}