blob: f3a59e7fd1094bb8d3c1cb27f820c1fa51558b9d [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2export const event = "threadDelete";
pineafane625d782022-05-09 18:04:32 +01003
4export async function callback(client, thread) {
pineafan63fc5e22022-08-04 22:04:10 +01005 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger;
6 const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
7 const audit = auditLog.entries.filter(entry => entry.target.id === thread.id).first();
pineafane23c4ec2022-07-27 21:56:27 +01008 if (audit.executor.id === client.user.id) return;
pineafan63fc5e22022-08-04 22:04:10 +01009 const data = {
pineafane625d782022-05-09 18:04:32 +010010 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010011 type: "channelDelete",
12 displayName: "Thread Deleted",
13 calculateType: "channelUpdate",
pineafane625d782022-05-09 18:04:32 +010014 color: NucleusColors.red,
15 emoji: "CHANNEL.TEXT.DELETE",
16 timestamp: new Date().getTime()
17 },
18 list: {
pineafanda6e5342022-07-03 10:03:16 +010019 threadId:entry(thread.id, `\`${thread.id}\``),
pineafane625d782022-05-09 18:04:32 +010020 name: entry(thread.name, thread.name),
21 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
pineafan63fc5e22022-08-04 22:04:10 +010022 category: entry(thread.parent.parent ? thread.parent.parent.name : "None", thread.parent.parent ? renderChannel(thread.parent.parent) : "None"),
pineafane625d782022-05-09 18:04:32 +010023 autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })),
24 membersInThread: entry(thread.memberCount, thread.memberCount),
25 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
26 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
27 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
28 },
29 hidden: {
30 guild: thread.guild.id
31 }
pineafan63fc5e22022-08-04 22:04:10 +010032 };
pineafan4edb7762022-06-26 19:21:04 +010033 log(data);
pineafane625d782022-05-09 18:04:32 +010034}