blob: f56e1bb5d1bf01f56190b56a9d08fa2dea8cc6e5 [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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05008 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
9 if (!await isLogging(thread.guild.id, "channelUpdate")) return;
TheCodedProfa16d1672023-01-18 18:58:34 -050010 const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadCreate))
PineaFan638eb132023-01-19 10:41:22 +000011 .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050012 if (auditLog.executor!.id === client.user!.id) return;
Skyler Greyf21323a2022-08-13 23:58:22 +010013 const category = thread.parent
14 ? entry(
15 thread.parent.parent ? thread.parent.parent.name : "None",
16 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
17 )
18 : entry(null, "Uncategorised");
pineafan63fc5e22022-08-04 22:04:10 +010019 const data = {
20 meta: {
21 type: "channelCreate",
22 displayName: "Thread Created",
23 calculateType: "channelUpdate",
24 color: NucleusColors.green,
25 emoji: "CHANNEL.TEXT.CREATE",
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050026 timestamp: thread.createdTimestamp ?? Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010027 },
28 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010029 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010030 name: entry(thread.name, renderChannel(thread)),
TheCodedProfa16d1672023-01-18 18:58:34 -050031 parentChannel: entry(thread.parentId, renderChannel(thread.parent!)),
pineafan0f5cc782022-08-12 21:55:42 +010032 category: category,
Skyler Grey75ea9172022-08-06 10:22:23 +010033 autoArchiveDuration: entry(
34 thread.autoArchiveDuration,
pineafan0f5cc782022-08-12 21:55:42 +010035 humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, {
Skyler Grey75ea9172022-08-06 10:22:23 +010036 round: true
37 })
38 ),
TheCodedProfa16d1672023-01-18 18:58:34 -050039 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
40 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp!))
pineafan63fc5e22022-08-04 22:04:10 +010041 },
42 hidden: {
43 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010044 }
pineafan63fc5e22022-08-04 22:04:10 +010045 };
46 log(data);
pineafane625d782022-05-09 18:04:32 +010047}