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) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger; |
| 6 | const auditLog = await getAuditLog(thread.guild, "THREAD_UPDATE"); |
| 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: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +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)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 22 | category: entry(thread.parent.parent ? thread.parent.parent.name : "None", thread.parent.parent ? renderChannel(thread.parent.parent) : "None"), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 23 | autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })), |
| 24 | membersInThread: entry(thread.memberCount, thread.memberCount), |
| 25 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 26 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)), |
| 27 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 28 | }, |
| 29 | hidden: { |
| 30 | guild: thread.guild.id |
| 31 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 32 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 33 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 34 | } |