pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 1 | import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js"; |
| 2 | // @ts-expect-error |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import humanizeDuration from "humanize-duration"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 4 | // @ts-expect-error |
| 5 | import type { HaikuClient } from "jshaiku" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | export const event = "threadCreate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 8 | export async function callback(client: HaikuClient, thread: ThreadChannel) { |
| 9 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE"); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 11 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === thread.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | if (audit.executor.id === client.user.id) return; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 13 | 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") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 27 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | name: entry(thread.name, renderChannel(thread)), |
| 29 | parentChannel: entry(thread.parentId, renderChannel(thread.parent)), |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 30 | category: category, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 31 | autoArchiveDuration: entry( |
| 32 | thread.autoArchiveDuration, |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame^] | 33 | humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | round: true |
| 35 | }) |
| 36 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 37 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 38 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }, |
| 40 | hidden: { |
| 41 | guild: thread.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 42 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | }; |
| 44 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 45 | } |