blob: 144dc84215a4042e398bf2698903c79f472e09c8 [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 Grey11236ba2022-08-08 21:13:33 +01005 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = after.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01006 const auditLog = await getAuditLog(after.guild, "THREAD_UPDATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
pineafan63fc5e22022-08-04 22:04:10 +01008 if (audit.executor.id === client.user.id) return;
9 const list = {
Skyler Grey75ea9172022-08-06 10:22:23 +010010 threadId: entry(after.id, `\`${after.id}\``),
pineafan63fc5e22022-08-04 22:04:10 +010011 thread: entry(after.name, renderChannel(after)),
12 parentChannel: entry(after.parentId, renderChannel(after.parent))
13 };
14 if (before.name !== after.name) {
Skyler Grey11236ba2022-08-08 21:13:33 +010015 list.name = entry([before.name, after.name], `${before.name} -> ${after.name}`);
pineafan63fc5e22022-08-04 22:04:10 +010016 }
17 if (before.autoArchiveDuration !== after.autoArchiveDuration) {
Skyler Grey75ea9172022-08-06 10:22:23 +010018 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 );
pineafan63fc5e22022-08-04 22:04:10 +010026 }
27 if (before.rateLimitPerUser !== after.rateLimitPerUser) {
Skyler Grey75ea9172022-08-06 10:22:23 +010028 list.slowmode = entry(
29 [before.rateLimitPerUser, after.rateLimitPerUser],
Skyler Grey11236ba2022-08-08 21:13:33 +010030 `${humanizeDuration(before.rateLimitPerUser * 1000)} -> ${humanizeDuration(after.rateLimitPerUser * 1000)}`
Skyler Grey75ea9172022-08-06 10:22:23 +010031 );
pineafan63fc5e22022-08-04 22:04:10 +010032 }
33 if (!(Object.keys(list).length - 3)) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010034 list.updated = entry(new Date().getTime(), renderDelta(new Date().getTime()));
Skyler Grey75ea9172022-08-06 10:22:23 +010035 list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
pineafan63fc5e22022-08-04 22:04:10 +010036 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
pineafane625d782022-05-09 18:04:32 +010048 }
pineafan63fc5e22022-08-04 22:04:10 +010049 };
50 log(data);
pineafane625d782022-05-09 18:04:32 +010051}