blob: 89a721c37960af84f338cd11eee064d205b325d0 [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) {
pineafan63fc5e22022-08-04 22:04:10 +01005 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
pineafane625d782022-05-09 18:04:32 +010038 }
pineafan63fc5e22022-08-04 22:04:10 +010039 };
40 log(data);
pineafane625d782022-05-09 18:04:32 +010041}