blob: cefaf3b44154e56201e4334efc1c24aa7e505019 [file] [log] [blame]
TheCodedProfa16d1672023-01-18 18:58:34 -05001import { AuditLogEvent, GuildAuditLogsEntry, ThreadChannel } from "discord.js";
pineafan0f5cc782022-08-12 21:55:42 +01002// @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) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05008 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00009 if (!(await isLogging(thread.guild.id, "channelUpdate"))) return;
10 const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadCreate)).filter(
11 (entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id
12 )[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050013 if (auditLog.executor!.id === client.user!.id) return;
Skyler Greyf21323a2022-08-13 23:58:22 +010014 const category = thread.parent
15 ? entry(
16 thread.parent.parent ? thread.parent.parent.name : "None",
17 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
18 )
19 : entry(null, "Uncategorised");
pineafan63fc5e22022-08-04 22:04:10 +010020 const data = {
21 meta: {
22 type: "channelCreate",
23 displayName: "Thread Created",
24 calculateType: "channelUpdate",
25 color: NucleusColors.green,
26 emoji: "CHANNEL.TEXT.CREATE",
TheCodedProf6ec331b2023-02-20 12:13:06 -050027 timestamp: thread.createdTimestamp ?? Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010030 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010031 name: entry(thread.name, renderChannel(thread)),
TheCodedProfa16d1672023-01-18 18:58:34 -050032 parentChannel: entry(thread.parentId, renderChannel(thread.parent!)),
pineafan0f5cc782022-08-12 21:55:42 +010033 category: category,
Skyler Grey75ea9172022-08-06 10:22:23 +010034 autoArchiveDuration: entry(
35 thread.autoArchiveDuration,
pineafan0f5cc782022-08-12 21:55:42 +010036 humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, {
Skyler Grey75ea9172022-08-06 10:22:23 +010037 round: true
38 })
39 ),
TheCodedProfa16d1672023-01-18 18:58:34 -050040 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
41 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp!))
pineafan63fc5e22022-08-04 22:04:10 +010042 },
43 hidden: {
44 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010045 }
pineafan63fc5e22022-08-04 22:04:10 +010046 };
47 log(data);
pineafane625d782022-05-09 18:04:32 +010048}