blob: da3cbaeb1cbc117d844963a85968f48b6054fff2 [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 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_CREATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const audit = auditLog.entries.filter((entry) => entry.target.id === thread.id).first();
pineafan63fc5e22022-08-04 22:04:10 +01008 if (audit.executor.id === client.user.id) return;
9 const data = {
10 meta: {
11 type: "channelCreate",
12 displayName: "Thread Created",
13 calculateType: "channelUpdate",
14 color: NucleusColors.green,
15 emoji: "CHANNEL.TEXT.CREATE",
16 timestamp: thread.createdTimestamp
17 },
18 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010019 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010020 name: entry(thread.name, renderChannel(thread)),
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 ),
pineafan63fc5e22022-08-04 22:04:10 +010032 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010033 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010034 },
35 hidden: {
36 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010037 }
pineafan63fc5e22022-08-04 22:04:10 +010038 };
39 log(data);
pineafane625d782022-05-09 18:04:32 +010040}