blob: e8849c9cf7b317a60c96055824ad86ee81787de4 [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";
pineafan0f5cc782022-08-12 21:55:42 +01004// @ts-expect-error
5import type { HaikuClient } from "jshaiku"
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "threadCreate";
pineafane625d782022-05-09 18:04:32 +01007
pineafan0f5cc782022-08-12 21:55:42 +01008export async function callback(client: HaikuClient, thread: ThreadChannel) {
9 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE");
pineafan0f5cc782022-08-12 21:55:42 +010011 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010012 if (audit.executor.id === client.user.id) return;
pineafan0f5cc782022-08-12 21:55:42 +010013 const category = thread.parent ? entry(
14 thread.parent.parent ? thread.parent.parent.name : "None",
15 thread.parent.parent ? renderChannel(thread.parent.parent) : "None"
16 ) : entry(null, "Uncategorised")
pineafan63fc5e22022-08-04 22:04:10 +010017 const data = {
18 meta: {
19 type: "channelCreate",
20 displayName: "Thread Created",
21 calculateType: "channelUpdate",
22 color: NucleusColors.green,
23 emoji: "CHANNEL.TEXT.CREATE",
24 timestamp: thread.createdTimestamp
25 },
26 list: {
Skyler Grey75ea9172022-08-06 10:22:23 +010027 threadId: entry(thread.id, `\`${thread.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010028 name: entry(thread.name, renderChannel(thread)),
29 parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
pineafan0f5cc782022-08-12 21:55:42 +010030 category: category,
Skyler Grey75ea9172022-08-06 10:22:23 +010031 autoArchiveDuration: entry(
32 thread.autoArchiveDuration,
pineafan0f5cc782022-08-12 21:55:42 +010033 humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, {
Skyler Grey75ea9172022-08-06 10:22:23 +010034 round: true
35 })
36 ),
pineafan63fc5e22022-08-04 22:04:10 +010037 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010038 created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010039 },
40 hidden: {
41 guild: thread.guild.id
pineafane625d782022-05-09 18:04:32 +010042 }
pineafan63fc5e22022-08-04 22:04:10 +010043 };
44 log(data);
pineafane625d782022-05-09 18:04:32 +010045}