blob: ff36ce0bb14e9ed510b92a4deaecc9f17d73e1ec [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2export const event = "threadUpdate";
pineafane625d782022-05-09 18:04:32 +01003
4export async function callback(client, before, after) {
Skyler Grey75ea9172022-08-06 10:22:23 +01005 const {
6 getAuditLog,
7 log,
8 NucleusColors,
9 entry,
10 renderUser,
11 renderDelta,
12 renderChannel
13 } = after.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010014 const auditLog = await getAuditLog(after.guild, "THREAD_UPDATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010015 const audit = auditLog.entries
16 .filter((entry) => entry.target.id === after.id)
17 .first();
pineafan63fc5e22022-08-04 22:04:10 +010018 if (audit.executor.id === client.user.id) return;
19 const list = {
Skyler Grey75ea9172022-08-06 10:22:23 +010020 threadId: entry(after.id, `\`${after.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010021 thread: entry(after.name, renderChannel(after)),
22 parentChannel: entry(after.parentId, renderChannel(after.parent))
23 };
24 if (before.name !== after.name) {
Skyler Grey75ea9172022-08-06 10:22:23 +010025 list.name = entry(
26 [before.name, after.name],
27 `${before.name} -> ${after.name}`
28 );
pineafan63fc5e22022-08-04 22:04:10 +010029 }
30 if (before.autoArchiveDuration !== after.autoArchiveDuration) {
Skyler Grey75ea9172022-08-06 10:22:23 +010031 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 );
pineafan63fc5e22022-08-04 22:04:10 +010039 }
40 if (before.rateLimitPerUser !== after.rateLimitPerUser) {
Skyler Grey75ea9172022-08-06 10:22:23 +010041 list.slowmode = entry(
42 [before.rateLimitPerUser, after.rateLimitPerUser],
43 `${humanizeDuration(
44 before.rateLimitPerUser * 1000
45 )} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`
46 );
pineafan63fc5e22022-08-04 22:04:10 +010047 }
48 if (!(Object.keys(list).length - 3)) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010049 list.updated = entry(
50 new Date().getTime(),
51 renderDelta(new Date().getTime())
52 );
53 list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
pineafan63fc5e22022-08-04 22:04:10 +010054 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
pineafane625d782022-05-09 18:04:32 +010066 }
pineafan63fc5e22022-08-04 22:04:10 +010067 };
68 log(data);
pineafane625d782022-05-09 18:04:32 +010069}