pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import humanizeDuration from "humanize-duration"; |
| 2 | export const event = "threadDelete"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 3 | |
| 4 | export async function callback(client, thread) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 7 | const audit = auditLog.entries.filter((entry) => entry.target.id === thread.id).first(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 8 | if (audit.executor.id === client.user.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | const data = { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 10 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | type: "channelDelete", |
| 12 | displayName: "Thread Deleted", |
| 13 | calculateType: "channelUpdate", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 14 | color: NucleusColors.red, |
| 15 | emoji: "CHANNEL.TEXT.DELETE", |
| 16 | timestamp: new Date().getTime() |
| 17 | }, |
| 18 | list: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 19 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 20 | name: entry(thread.name, thread.name), |
| 21 | parentChannel: entry(thread.parentId, renderChannel(thread.parent)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | category: entry( |
| 23 | thread.parent.parent ? thread.parent.parent.name : "None", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 24 | thread.parent.parent ? renderChannel(thread.parent.parent) : "None" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 25 | ), |
| 26 | autoArchiveDuration: entry( |
| 27 | thread.autoArchiveDuration, |
| 28 | humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { |
| 29 | round: true |
| 30 | }) |
| 31 | ), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 32 | membersInThread: entry(thread.memberCount, thread.memberCount), |
| 33 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 34 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)), |
| 35 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 36 | }, |
| 37 | hidden: { |
| 38 | guild: thread.guild.id |
| 39 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 40 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 41 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 42 | } |