blob: d6b9e93e0831313d6f53cff579e72d6a0d9cc891 [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) {
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_CREATE");
7 const audit = auditLog.entries.filter(entry => entry.target.id === thread.id).first();
8 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: {
19 threadId:entry(thread.id, `\`${thread.id}\``),
20 name: entry(thread.name, renderChannel(thread)),
21 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
22 category: entry(thread.parent.parent ? thread.parent.parent.name : "None", thread.parent.parent ? renderChannel(thread.parent.parent) : "None"),
23 autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })),
24 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
25 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
26 },
27 hidden: {
28 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010029 }
pineafan63fc5e22022-08-04 22:04:10 +010030 };
31 log(data);
pineafane625d782022-05-09 18:04:32 +010032}