blob: 0077eff7d7db61755d44df2ef37e4e020c235e1f [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 Grey75ea9172022-08-06 10:22:23 +01005 const {
6 getAuditLog,
7 log,
8 NucleusColors,
9 entry,
10 renderUser,
11 renderDelta,
12 renderChannel
13 } = thread.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010014 const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010015 const audit = auditLog.entries
16 .filter((entry) => entry.target.id === thread.id)
17 .first();
pineafane23c4ec2022-07-27 21:56:27 +010018 if (audit.executor.id === client.user.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010019 const data = {
pineafane625d782022-05-09 18:04:32 +010020 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010021 type: "channelDelete",
22 displayName: "Thread Deleted",
23 calculateType: "channelUpdate",
pineafane625d782022-05-09 18:04:32 +010024 color: NucleusColors.red,
25 emoji: "CHANNEL.TEXT.DELETE",
26 timestamp: new Date().getTime()
27 },
28 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010029 threadId: entry(thread.id, `\`${thread.id}\``),
pineafane625d782022-05-09 18:04:32 +010030 name: entry(thread.name, thread.name),
31 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
Skyler Grey75ea9172022-08-06 10:22:23 +010032 category: entry(
33 thread.parent.parent ? thread.parent.parent.name : "None",
34 thread.parent.parent
35 ? renderChannel(thread.parent.parent)
36 : "None"
37 ),
38 autoArchiveDuration: entry(
39 thread.autoArchiveDuration,
40 humanizeDuration(thread.autoArchiveDuration * 60 * 1000, {
41 round: true
42 })
43 ),
pineafane625d782022-05-09 18:04:32 +010044 membersInThread: entry(thread.memberCount, thread.memberCount),
45 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010046 created: entry(
47 thread.createdTimestamp,
48 renderDelta(thread.createdTimestamp)
49 ),
50 deleted: entry(
51 new Date().getTime(),
52 renderDelta(new Date().getTime())
53 )
pineafane625d782022-05-09 18:04:32 +010054 },
55 hidden: {
56 guild: thread.guild.id
57 }
pineafan63fc5e22022-08-04 22:04:10 +010058 };
pineafan4edb7762022-06-26 19:21:04 +010059 log(data);
pineafane625d782022-05-09 18:04:32 +010060}