blob: c166f8623f9eb991aecf0880ead0de3b023cbd57 [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js";
2// @ts-expect-error
pineafan63fc5e22022-08-04 22:04:10 +01003import humanizeDuration from "humanize-duration";
PineaFan64486c42022-12-28 09:21:04 +00004import type { HaikuClient } from "../utils/haiku/index.js";
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "threadDelete";
pineafane625d782022-05-09 18:04:32 +01006
pineafan0f5cc782022-08-12 21:55:42 +01007export async function callback(client: HaikuClient, thread: ThreadChannel) {
8 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
pineafan0f5cc782022-08-12 21:55:42 +010010 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first();
pineafane23c4ec2022-07-27 21:56:27 +010011 if (audit.executor.id === client.user.id) return;
Skyler Greyf21323a2022-08-13 23:58:22 +010012 const category = thread.parent
13 ? entry(
14 thread.parent.parent ? thread.parent.parent.name : "None",
15 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
16 )
17 : entry(null, "Uncategorised");
pineafan63fc5e22022-08-04 22:04:10 +010018 const data = {
pineafane625d782022-05-09 18:04:32 +010019 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010020 type: "channelDelete",
21 displayName: "Thread Deleted",
22 calculateType: "channelUpdate",
pineafane625d782022-05-09 18:04:32 +010023 color: NucleusColors.red,
24 emoji: "CHANNEL.TEXT.DELETE",
25 timestamp: new Date().getTime()
26 },
27 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010028 threadId: entry(thread.id, `\`${thread.id}\``),
pineafane625d782022-05-09 18:04:32 +010029 name: entry(thread.name, thread.name),
pineafan0f5cc782022-08-12 21:55:42 +010030 parentChannel: entry(thread.parentId, thread.parent ? renderChannel(thread.parent) : "*None*"),
31 category: category,
Skyler Grey75ea9172022-08-06 10:22:23 +010032 autoArchiveDuration: entry(
33 thread.autoArchiveDuration,
pineafan0f5cc782022-08-12 21:55:42 +010034 humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, {
Skyler Grey75ea9172022-08-06 10:22:23 +010035 round: true
36 })
37 ),
pineafane625d782022-05-09 18:04:32 +010038 membersInThread: entry(thread.memberCount, thread.memberCount),
39 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010040 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
41 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafane625d782022-05-09 18:04:32 +010042 },
43 hidden: {
44 guild: thread.guild.id
45 }
pineafan63fc5e22022-08-04 22:04:10 +010046 };
pineafan4edb7762022-06-26 19:21:04 +010047 log(data);
pineafane625d782022-05-09 18:04:32 +010048}