pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 1 | import humanizeDuration from 'humanize-duration'; |
| 2 | export const event = 'threadUpdate' |
| 3 | |
| 4 | export async function callback(client, before, after) { |
| 5 | try { |
| 6 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = after.client.logger |
| 7 | let auditLog = await getAuditLog(after.guild, 'THREAD_UPDATE'); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 8 | let audit = auditLog.entries.filter(entry => entry.target.id === after.id).first(); |
| 9 | if (audit.executor.id === client.user.id) return; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 10 | let list = { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 11 | threadId:entry(after.id, `\`${after.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 12 | thread: entry(after.name, renderChannel(after)), |
| 13 | parentChannel: entry(after.parentId, renderChannel(after.parent)), |
| 14 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 15 | if (before.name !== after.name) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 16 | list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`); |
| 17 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 18 | if (before.autoArchiveDuration !== after.autoArchiveDuration) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 19 | list["autoArchiveDuration"] = entry([before.autoArchiveDuration, after.autoArchiveDuration], `${humanizeDuration(before.autoArchiveDuration * 60 * 1000, { round: true })} -> ${humanizeDuration(after.autoArchiveDuration * 60 * 1000, { round: true })}`); |
| 20 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 21 | if (before.rateLimitPerUser !== after.rateLimitPerUser) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 22 | list["slowmode"] = entry([before.rateLimitPerUser, after.rateLimitPerUser], `${humanizeDuration(before.rateLimitPerUser * 1000)} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`); |
| 23 | } |
| 24 | if (!(Object.keys(list).length - 3)) return; |
| 25 | list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 26 | list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor)) |
| 27 | let data = { |
| 28 | meta: { |
| 29 | type: 'channelUpdate', |
| 30 | displayName: 'Thread Edited', |
| 31 | calculateType: 'channelUpdate', |
| 32 | color: NucleusColors.yellow, |
| 33 | emoji: "CHANNEL.TEXT.EDIT", |
| 34 | timestamp: new Date().getTime() |
| 35 | }, |
| 36 | list: list, |
| 37 | hidden: { |
| 38 | guild: after.guild.id |
| 39 | } |
| 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 | } catch {} |
| 43 | } |