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 = "threadDelete"; |
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) { |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 8 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 9 | const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadDelete)) |
| 10 | .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0] as GuildAuditLogsEntry; |
| 11 | if (auditLog.executor!.id === client.user!.id) return; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 12 | const category = thread.parent |
| 13 | ? entry( |
| 14 | thread.parent.parent ? thread.parent.parent.name : "None", |
| 15 | thread.parent.parent ? renderChannel(thread.parent.parent) : "None" |
| 16 | ) |
| 17 | : entry(null, "Uncategorised"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | const data = { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 19 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | type: "channelDelete", |
| 21 | displayName: "Thread Deleted", |
| 22 | calculateType: "channelUpdate", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 23 | color: NucleusColors.red, |
| 24 | emoji: "CHANNEL.TEXT.DELETE", |
| 25 | timestamp: new Date().getTime() |
| 26 | }, |
| 27 | list: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 28 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 29 | name: entry(thread.name, thread.name), |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 30 | parentChannel: entry(thread.parentId, thread.parent ? renderChannel(thread.parent) : "*None*"), |
| 31 | category: category, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 32 | autoArchiveDuration: entry( |
| 33 | thread.autoArchiveDuration, |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 34 | humanizeDuration((thread.autoArchiveDuration ?? 0) * 60 * 1000, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | round: true |
| 36 | }) |
| 37 | ), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 38 | membersInThread: entry(thread.memberCount, thread.memberCount!.toString()), |
| 39 | deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 40 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp!)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 41 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 42 | }, |
| 43 | hidden: { |
| 44 | guild: thread.guild.id |
| 45 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 46 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 47 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 48 | } |