blob: 4e1319317f9f37587359e028f20219a08cd4f107 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
2export const event = 'threadUpdate'
3
4export 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 = {
pineafanda6e5342022-07-03 10:03:16 +010011 threadId:entry(after.id, `\`${after.id}\``),
pineafane625d782022-05-09 18:04:32 +010012 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 }
pineafan4edb7762022-06-26 19:21:04 +010041 log(data);
pineafane625d782022-05-09 18:04:32 +010042 } catch {}
43}