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