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'); |
| 8 | let audit = auditLog.entries.filter(entry => entry.target.id == after.id).first(); |
| 9 | if (audit.executor.id == client.user.id) return; |
| 10 | let list = { |
| 11 | id: entry(after.id, `\`${after.id}\``), |
| 12 | thread: entry(after.name, renderChannel(after)), |
| 13 | parentChannel: entry(after.parentId, renderChannel(after.parent)), |
| 14 | } |
| 15 | if (before.name != after.name) { |
| 16 | list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`); |
| 17 | } |
| 18 | if (before.autoArchiveDuration != after.autoArchiveDuration) { |
| 19 | list["autoArchiveDuration"] = entry([before.autoArchiveDuration, after.autoArchiveDuration], `${humanizeDuration(before.autoArchiveDuration * 60 * 1000, { round: true })} -> ${humanizeDuration(after.autoArchiveDuration * 60 * 1000, { round: true })}`); |
| 20 | } |
| 21 | if (before.rateLimitPerUser != after.rateLimitPerUser) { |
| 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 | } |
| 41 | log(data, after.client); |
| 42 | } catch {} |
| 43 | } |