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; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 6 | if (client.noLog.includes(`${message.guild.id}/${message.channel.id}/${message.id}`)) return; |
| 7 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = |
| 8 | message.channel.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 10 | const audit = auditLog.entries.filter((entry) => entry.target.id === message.author.id).first(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 11 | if (audit) { |
| 12 | if (audit.createdAt - 100 < new Date().getTime()) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 13 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | message.reference = message.reference || {}; |
| 15 | let content = message.cleanContent; |
| 16 | content.replace("`", "\\`"); |
| 17 | if (content.length > 256) content = content.substring(0, 253) + "..."; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 18 | const attachments = |
| 19 | message.attachments.size + |
| 20 | ( |
| 21 | message.content.match( |
| 22 | /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi |
| 23 | ) ?? [] |
| 24 | ).length; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 25 | let attachmentJump = ""; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 26 | const config = (await client.database.guilds.read(message.guild.id)).logging.attachments.saved[ |
| 27 | message.channel.id + message.id |
| 28 | ]; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 29 | if (config) { |
| 30 | attachmentJump = ` [[View attachments]](${config})`; |
| 31 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | const data = { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 33 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | type: "messageDelete", |
| 35 | displayName: "Message Deleted", |
| 36 | calculateType: "messageDelete", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | color: NucleusColors.red, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 38 | emoji: "MESSAGE.DELETE", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 39 | timestamp: new Date().getTime() |
| 40 | }, |
| 41 | separate: { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 42 | start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*" |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 43 | }, |
| 44 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 45 | messageId: entry(message.id, `\`${message.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 46 | sentBy: entry(message.author.id, renderUser(message.author)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 47 | sentIn: entry(message.channel.id, renderChannel(message.channel)), |
| 48 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 49 | mentions: message.mentions.users.size, |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 50 | attachments: entry(attachments, attachments + attachmentJump), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 51 | repliedTo: entry( |
| 52 | message.reference.messageId || null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 53 | message.reference.messageId |
| 54 | ? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})` |
| 55 | : "None" |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 56 | ) |
| 57 | }, |
| 58 | hidden: { |
| 59 | guild: message.channel.guild.id |
| 60 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 61 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 62 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 63 | } catch (e) { |
| 64 | console.log(e); |
| 65 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 66 | } |