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 | 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 | } = after.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const auditLog = await getAuditLog(after.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 === after.id) |
| 17 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | if (audit.executor.id === client.user.id) return; |
| 19 | const list = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 20 | threadId: entry(after.id, `\`${after.id}\``), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 21 | thread: entry(after.name, renderChannel(after)), |
| 22 | parentChannel: entry(after.parentId, renderChannel(after.parent)) |
| 23 | }; |
| 24 | if (before.name !== after.name) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 25 | list.name = entry( |
| 26 | [before.name, after.name], |
| 27 | `${before.name} -> ${after.name}` |
| 28 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | } |
| 30 | if (before.autoArchiveDuration !== after.autoArchiveDuration) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 31 | list.autoArchiveDuration = entry( |
| 32 | [before.autoArchiveDuration, after.autoArchiveDuration], |
| 33 | `${humanizeDuration(before.autoArchiveDuration * 60 * 1000, { |
| 34 | round: true |
| 35 | })} -> ${humanizeDuration(after.autoArchiveDuration * 60 * 1000, { |
| 36 | round: true |
| 37 | })}` |
| 38 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | } |
| 40 | if (before.rateLimitPerUser !== after.rateLimitPerUser) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 41 | list.slowmode = entry( |
| 42 | [before.rateLimitPerUser, after.rateLimitPerUser], |
| 43 | `${humanizeDuration( |
| 44 | before.rateLimitPerUser * 1000 |
| 45 | )} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}` |
| 46 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | } |
| 48 | if (!(Object.keys(list).length - 3)) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 49 | list.updated = entry( |
| 50 | new Date().getTime(), |
| 51 | renderDelta(new Date().getTime()) |
| 52 | ); |
| 53 | list.updatedBy = entry(audit.executor.id, renderUser(audit.executor)); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 54 | const data = { |
| 55 | meta: { |
| 56 | type: "channelUpdate", |
| 57 | displayName: "Thread Edited", |
| 58 | calculateType: "channelUpdate", |
| 59 | color: NucleusColors.yellow, |
| 60 | emoji: "CHANNEL.TEXT.EDIT", |
| 61 | timestamp: new Date().getTime() |
| 62 | }, |
| 63 | list: list, |
| 64 | hidden: { |
| 65 | guild: after.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 66 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 67 | }; |
| 68 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 69 | } |