blob: 4fdedcb002328757a2f909b6a0a818ca487ea575 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2export const event = "threadCreate";
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_CREATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010015 const audit = auditLog.entries
16 .filter((entry) => entry.target.id === thread.id)
17 .first();
pineafan63fc5e22022-08-04 22:04:10 +010018 if (audit.executor.id === client.user.id) return;
19 const data = {
20 meta: {
21 type: "channelCreate",
22 displayName: "Thread Created",
23 calculateType: "channelUpdate",
24 color: NucleusColors.green,
25 emoji: "CHANNEL.TEXT.CREATE",
26 timestamp: thread.createdTimestamp
27 },
28 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010029 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010030 name: entry(thread.name, renderChannel(thread)),
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 ),
pineafan63fc5e22022-08-04 22:04:10 +010044 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010045 created: entry(
46 thread.createdTimestamp,
47 renderDelta(thread.createdTimestamp)
48 )
pineafan63fc5e22022-08-04 22:04:10 +010049 },
50 hidden: {
51 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010052 }
pineafan63fc5e22022-08-04 22:04:10 +010053 };
54 log(data);
pineafane625d782022-05-09 18:04:32 +010055}