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