TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 1 | import { AuditLogEvent, GuildAuditLogsEntry, ThreadChannel } from "discord.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 2 | // @ts-expect-error |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import humanizeDuration from "humanize-duration"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 4 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | export const event = "threadCreate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 7 | export async function callback(client: NucleusClient, thread: ThreadChannel) { |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 8 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
| 9 | if (!await isLogging(thread.guild.id, "channelUpdate")) return; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 10 | const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadCreate)) |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 11 | .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 12 | if (auditLog.executor!.id === client.user!.id) return; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 13 | 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"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 19 | const data = { |
| 20 | meta: { |
| 21 | type: "channelCreate", |
| 22 | displayName: "Thread Created", |
| 23 | calculateType: "channelUpdate", |
| 24 | color: NucleusColors.green, |
| 25 | emoji: "CHANNEL.TEXT.CREATE", |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 26 | timestamp: thread.createdTimestamp ?? Date.now() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 27 | }, |
| 28 | list: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 29 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | name: entry(thread.name, renderChannel(thread)), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 31 | parentChannel: entry(thread.parentId, renderChannel(thread.parent!)), |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 32 | category: category, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 33 | autoArchiveDuration: entry( |
| 34 | thread.autoArchiveDuration, |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 35 | humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 36 | round: true |
| 37 | }) |
| 38 | ), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 39 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 40 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp!)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 41 | }, |
| 42 | hidden: { |
| 43 | guild: thread.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 44 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 45 | }; |
| 46 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 47 | } |