blob: 1f1b758f59a9bb08d44d75011888e0f1c4e20e1b [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js";
2// @ts-expect-error
pineafan63fc5e22022-08-04 22:04:10 +01003import humanizeDuration from "humanize-duration";
PineaFan752af462022-12-31 21:59:38 +00004import type { NucleusClient } from "../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "threadCreate";
pineafane625d782022-05-09 18:04:32 +01006
PineaFan752af462022-12-31 21:59:38 +00007export async function callback(client: NucleusClient, thread: ThreadChannel) {
pineafan0f5cc782022-08-12 21:55:42 +01008 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE");
pineafan0f5cc782022-08-12 21:55:42 +010010 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010011 if (audit.executor.id === client.user.id) return;
Skyler Greyf21323a2022-08-13 23:58:22 +010012 const category = thread.parent
13 ? entry(
14 thread.parent.parent ? thread.parent.parent.name : "None",
15 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
16 )
17 : entry(null, "Uncategorised");
pineafan63fc5e22022-08-04 22:04:10 +010018 const data = {
19 meta: {
20 type: "channelCreate",
21 displayName: "Thread Created",
22 calculateType: "channelUpdate",
23 color: NucleusColors.green,
24 emoji: "CHANNEL.TEXT.CREATE",
25 timestamp: thread.createdTimestamp
26 },
27 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010028 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010029 name: entry(thread.name, renderChannel(thread)),
30 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
pineafan0f5cc782022-08-12 21:55:42 +010031 category: category,
Skyler Grey75ea9172022-08-06 10:22:23 +010032 autoArchiveDuration: entry(
33 thread.autoArchiveDuration,
pineafan0f5cc782022-08-12 21:55:42 +010034 humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, {
Skyler Grey75ea9172022-08-06 10:22:23 +010035 round: true
36 })
37 ),
pineafan63fc5e22022-08-04 22:04:10 +010038 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010039 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010040 },
41 hidden: {
42 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010043 }
pineafan63fc5e22022-08-04 22:04:10 +010044 };
45 log(data);
pineafane625d782022-05-09 18:04:32 +010046}