blob: bfae11ae4437e8115213b5981a6309d4d892284a [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) {
Skyler Grey11236ba2022-08-08 21:13:33 +01005 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01006 const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01007 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: {
Skyler Grey75ea9172022-08-06 10:22:23 +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)),
Skyler Grey75ea9172022-08-06 10:22:23 +010022 category: entry(
23 thread.parent.parent ? thread.parent.parent.name : "None",
Skyler Grey11236ba2022-08-08 21:13:33 +010024 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
Skyler Grey75ea9172022-08-06 10:22:23 +010025 ),
26 autoArchiveDuration: entry(
27 thread.autoArchiveDuration,
28 humanizeDuration(thread.autoArchiveDuration * 60 * 1000, {
29 round: true
30 })
31 ),
pineafane625d782022-05-09 18:04:32 +010032 membersInThread: entry(thread.memberCount, thread.memberCount),
33 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010034 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
35 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafane625d782022-05-09 18:04:32 +010036 },
37 hidden: {
38 guild: thread.guild.id
39 }
pineafan63fc5e22022-08-04 22:04:10 +010040 };
pineafan4edb7762022-06-26 19:21:04 +010041 log(data);
pineafane625d782022-05-09 18:04:32 +010042}