pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 1 | export const event = "messageDelete"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 2 | |
| 3 | export async function callback(client, message) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 4 | try { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 5 | if (message.author.id === client.user.id) return; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 6 | if (client.noLog.includes(`${message.guild.id}/${message.channel.id}/${message.id}`)) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 7 | 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(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 10 | if (audit) { |
| 11 | if (audit.createdAt - 100 < new Date().getTime()) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 12 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 13 | 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 = { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 22 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 23 | type: "messageDelete", |
| 24 | displayName: "Message Deleted", |
| 25 | calculateType: "messageDelete", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 26 | color: NucleusColors.red, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 27 | emoji: "MESSAGE.DELETE", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 28 | timestamp: new Date().getTime() |
| 29 | }, |
| 30 | separate: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 31 | start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*" |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 32 | }, |
| 33 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 34 | messageId: entry(message.id, `\`${message.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 35 | 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, |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 39 | attachments: entry(attachments, attachments + attachmentJump), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 40 | 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 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 48 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 49 | log(data); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 50 | } catch(e) { console.log(e); } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 51 | } |