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