blob: 473fa52e5c6db5cc48f713fba434539ffee36df7 [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;
pineafan73a7c4a2022-07-24 10:38:04 +01006 if (client.noLog.includes(`${message.guild.id}/${message.channel.id}/${message.id}`)) return;
pineafan63fc5e22022-08-04 22:04:10 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = message.channel.client.logger;
8 const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
9 const audit = auditLog.entries.filter(entry => entry.target.id === message.author.id).first();
pineafane625d782022-05-09 18:04:32 +010010 if (audit) {
11 if (audit.createdAt - 100 < new Date().getTime()) return;
pineafan32767212022-03-14 21:27:39 +000012 }
pineafan63fc5e22022-08-04 22:04:10 +010013 message.reference = message.reference || {};
14 let content = message.cleanContent;
15 content.replace("`", "\\`");
16 if (content.length > 256) content = content.substring(0, 253) + "...";
17 const attachments = message.attachments.size + (message.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi) ?? []).length;
18 let attachmentJump = "";
19 const config = (await client.database.guilds.read(message.guild.id)).logging.attachments.saved[message.channel.id + message.id];
20 if (config) { attachmentJump = ` [[View attachments]](${config})`; }
21 const data = {
pineafane625d782022-05-09 18:04:32 +010022 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010023 type: "messageDelete",
24 displayName: "Message Deleted",
25 calculateType: "messageDelete",
pineafane625d782022-05-09 18:04:32 +010026 color: NucleusColors.red,
pineafan63fc5e22022-08-04 22:04:10 +010027 emoji: "MESSAGE.DELETE",
pineafane625d782022-05-09 18:04:32 +010028 timestamp: new Date().getTime()
29 },
30 separate: {
pineafan63fc5e22022-08-04 22:04:10 +010031 start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
pineafane625d782022-05-09 18:04:32 +010032 },
33 list: {
pineafanda6e5342022-07-03 10:03:16 +010034 messageId: entry(message.id, `\`${message.id}\``),
pineafane625d782022-05-09 18:04:32 +010035 sentBy: entry(message.author.id, renderUser(message.author)),
36 sentIn: entry(message.channel.id, renderChannel(message.channel)),
37 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
38 mentions: message.mentions.users.size,
pineafan02ba0232022-07-24 22:16:15 +010039 attachments: entry(attachments, attachments + attachmentJump),
pineafane625d782022-05-09 18:04:32 +010040 repliedTo: entry(
41 message.reference.messageId || null,
42 message.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})` : "None"
43 )
44 },
45 hidden: {
46 guild: message.channel.guild.id
47 }
pineafan63fc5e22022-08-04 22:04:10 +010048 };
pineafan4edb7762022-06-26 19:21:04 +010049 log(data);
pineafan63fc5e22022-08-04 22:04:10 +010050 } catch(e) { console.log(e); }
pineafan32767212022-03-14 21:27:39 +000051}