blob: 3c23739df850cabf2d36bb345ee2fff87df8fa46 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001export const event = 'messageDelete'
2
3export async function callback(client, message) {
pineafane625d782022-05-09 18:04:32 +01004 try {
5 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;
pineafane625d782022-05-09 18:04:32 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = message.channel.client.logger
8 let auditLog = await getAuditLog(message.guild, 'MEMBER_BAN_ADD')
9 let audit = auditLog.entries.filter(entry => entry.target.id == message.author.id).first();
10 if (audit) {
11 if (audit.createdAt - 100 < new Date().getTime()) return;
pineafan32767212022-03-14 21:27:39 +000012 }
pineafane625d782022-05-09 18:04:32 +010013 message.reference = message.reference || {}
14 let content = message.cleanContent
pineafan73a7c4a2022-07-24 10:38:04 +010015 content.replace(`\``, `\\\``)
pineafane625d782022-05-09 18:04:32 +010016 if (content.length > 256) content = content.substring(0, 253) + '...'
pineafan02ba0232022-07-24 22:16:15 +010017 let 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
pineafan73a7c4a2022-07-24 10:38:04 +010018 let attachmentJump = ""
19 let config = (await client.database.guilds.read(message.guild.id)).logging.attachments.saved[message.channel.id + message.id];
20 if (config) { attachmentJump = ` [[View attachments]](${config})` }
pineafane625d782022-05-09 18:04:32 +010021 let data = {
22 meta: {
23 type: 'messageDelete',
24 displayName: 'Message Deleted',
25 calculateType: 'messageDelete',
26 color: NucleusColors.red,
27 emoji: 'MESSAGE.DELETE',
28 timestamp: new Date().getTime()
29 },
30 separate: {
31 start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : '**Message:** *Message had no content*',
32 },
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 }
48 }
pineafan4edb7762022-06-26 19:21:04 +010049 log(data);
pineafan73a7c4a2022-07-24 10:38:04 +010050 } catch(e) { console.log(e) }
pineafan32767212022-03-14 21:27:39 +000051}