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