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