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