blob: 77e9dea901846523f8731c40c8c4fc525e76d7ad [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
2export const event = 'threadCreate'
3
4export async function callback(client, thread) {
5 try {
6 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger
7 let auditLog = await getAuditLog(thread.guild, 'THREAD_CREATE');
8 let audit = auditLog.entries.filter(entry => entry.target.id == thread.id).first();
9 if (audit.executor.id == client.user.id) return;
10 let data = {
11 meta: {
12 type: 'channelCreate',
13 displayName: 'Thread Created',
14 calculateType: 'channelUpdate',
15 color: NucleusColors.green,
16 emoji: "CHANNEL.TEXT.CREATE",
17 timestamp: thread.createdTimestamp
18 },
19 list: {
20 id: entry(thread.id, `\`${thread.id}\``),
21 name: entry(thread.name, renderChannel(thread)),
22 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
23 category: entry(thread.parent.parent ? thread.parent.parent.name : 'None', thread.parent.parent ? renderChannel(thread.parent.parent) : 'None'),
24 autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })),
25 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
26 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
27 },
28 hidden: {
29 guild: thread.guild.id
30 }
31 }
32 log(data, thread.client);
33 } catch {}
34}