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) { |
TheCodedProf | 4f79da1 | 2023-01-31 16:50:37 -0500 | [diff] [blame] | 7 | if (message.author.id === client.user!.id) return; |
| 8 | if (message.author.bot) return; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame^] | 9 | if (client.noLog.includes(`${message.guild!.id}/${message.channel.id}/${message.id}`)) return; |
TheCodedProf | 4f79da1 | 2023-01-31 16:50:37 -0500 | [diff] [blame] | 10 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
| 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; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | } |
TheCodedProf | 4f79da1 | 2023-01-31 16:50:37 -0500 | [diff] [blame] | 16 | const replyTo = message.reference; |
| 17 | let content = message.cleanContent; |
| 18 | content.replace("`", "\\`"); |
| 19 | if (content.length > 256) content = content.substring(0, 253) + "..."; |
| 20 | const attachments = |
| 21 | message.attachments.size + ( |
| 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; |
| 26 | let attachmentJump = ""; |
| 27 | const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[ |
| 28 | message.channel.id + message.id |
| 29 | ]; |
| 30 | if (config) { attachmentJump = ` [[View attachments]](${config})`; } |
| 31 | const data = { |
| 32 | meta: { |
| 33 | type: "messageDelete", |
| 34 | displayName: "Message Deleted", |
| 35 | calculateType: "messageDelete", |
| 36 | color: NucleusColors.red, |
| 37 | emoji: "MESSAGE.DELETE", |
| 38 | timestamp: new Date().getTime() |
| 39 | }, |
| 40 | separate: { |
| 41 | start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*" |
| 42 | }, |
| 43 | list: { |
| 44 | messageId: entry(message.id, `\`${message.id}\``), |
| 45 | sentBy: entry(message.author.id, renderUser(message.author)), |
| 46 | sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)), |
| 47 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 48 | mentions: message.mentions.users.size, |
| 49 | attachments: entry(attachments, attachments + attachmentJump), |
| 50 | repliedTo: entry( |
| 51 | replyTo ? replyTo.messageId! : null, |
| 52 | replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})` |
| 53 | : "None" |
| 54 | ) |
| 55 | }, |
| 56 | hidden: { |
| 57 | guild: message.guild!.id |
| 58 | } |
| 59 | }; |
| 60 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 61 | } |