blob: bc668f1e48e47cde78e9b06fd2b72b9931e97b4e [file] [log] [blame]
PineaFan64486c42022-12-28 09:21:04 +00001import type { HaikuClient } from "../utils/haiku/index.js";
pineafan0f5cc782022-08-12 21:55:42 +01002import type { GuildAuditLogsEntry, Message } from "discord.js";
3
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "messageDelete";
pineafan32767212022-03-14 21:27:39 +00005
pineafan0f5cc782022-08-12 21:55:42 +01006export async function callback(client: HaikuClient, message: Message) {
pineafane625d782022-05-09 18:04:32 +01007 try {
pineafane23c4ec2022-07-27 21:56:27 +01008 if (message.author.id === client.user.id) return;
pineafan0f5cc782022-08-12 21:55:42 +01009 if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
10 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
Skyler Greyf21323a2022-08-13 23:58:22 +010012 const audit = auditLog.entries
13 .filter((entry: GuildAuditLogsEntry) => entry.target!.id === message.author.id)
14 .first();
pineafane625d782022-05-09 18:04:32 +010015 if (audit) {
16 if (audit.createdAt - 100 < new Date().getTime()) return;
pineafan32767212022-03-14 21:27:39 +000017 }
pineafan0f5cc782022-08-12 21:55:42 +010018 const replyTo = message.reference;
pineafan63fc5e22022-08-04 22:04:10 +010019 let content = message.cleanContent;
20 content.replace("`", "\\`");
21 if (content.length > 256) content = content.substring(0, 253) + "...";
Skyler Grey75ea9172022-08-06 10:22:23 +010022 const attachments =
23 message.attachments.size +
24 (
25 message.content.match(
26 /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
27 ) ?? []
28 ).length;
pineafan63fc5e22022-08-04 22:04:10 +010029 let attachmentJump = "";
pineafan0f5cc782022-08-12 21:55:42 +010030 const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
Skyler Grey11236ba2022-08-08 21:13:33 +010031 message.channel.id + message.id
32 ];
Skyler Grey75ea9172022-08-06 10:22:23 +010033 if (config) {
34 attachmentJump = ` [[View attachments]](${config})`;
35 }
pineafan63fc5e22022-08-04 22:04:10 +010036 const data = {
pineafane625d782022-05-09 18:04:32 +010037 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010038 type: "messageDelete",
39 displayName: "Message Deleted",
40 calculateType: "messageDelete",
pineafane625d782022-05-09 18:04:32 +010041 color: NucleusColors.red,
pineafan63fc5e22022-08-04 22:04:10 +010042 emoji: "MESSAGE.DELETE",
pineafane625d782022-05-09 18:04:32 +010043 timestamp: new Date().getTime()
44 },
45 separate: {
Skyler Grey11236ba2022-08-08 21:13:33 +010046 start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
pineafane625d782022-05-09 18:04:32 +010047 },
48 list: {
pineafanda6e5342022-07-03 10:03:16 +010049 messageId: entry(message.id, `\`${message.id}\``),
pineafane625d782022-05-09 18:04:32 +010050 sentBy: entry(message.author.id, renderUser(message.author)),
Skyler Grey11236ba2022-08-08 21:13:33 +010051 sentIn: entry(message.channel.id, renderChannel(message.channel)),
52 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafane625d782022-05-09 18:04:32 +010053 mentions: message.mentions.users.size,
pineafan02ba0232022-07-24 22:16:15 +010054 attachments: entry(attachments, attachments + attachmentJump),
pineafane625d782022-05-09 18:04:32 +010055 repliedTo: entry(
pineafan0f5cc782022-08-12 21:55:42 +010056 replyTo,
57 replyTo
Skyler Greyf21323a2022-08-13 23:58:22 +010058 ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${
59 message.channel.id
60 }/${replyTo.messageId})`
Skyler Grey75ea9172022-08-06 10:22:23 +010061 : "None"
pineafane625d782022-05-09 18:04:32 +010062 )
63 },
64 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010065 guild: message.guild!.id
pineafane625d782022-05-09 18:04:32 +010066 }
pineafan63fc5e22022-08-04 22:04:10 +010067 };
pineafan4edb7762022-06-26 19:21:04 +010068 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010069 } catch (e) {
70 console.log(e);
71 }
pineafan32767212022-03-14 21:27:39 +000072}