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