blob: 8550ffe231d90218207c61560b2c1670f2e507ea [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');
pineafane23c4ec2022-07-27 21:56:27 +01008 let audit = auditLog.entries.filter(entry => entry.target.id === after.id).first();
9 if (audit.executor.id === client.user.id) return;
pineafane625d782022-05-09 18:04:32 +010010 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 }
pineafane23c4ec2022-07-27 21:56:27 +010015 if (before.name !== after.name) {
pineafane625d782022-05-09 18:04:32 +010016 list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
17 }
pineafane23c4ec2022-07-27 21:56:27 +010018 if (before.autoArchiveDuration !== after.autoArchiveDuration) {
pineafane625d782022-05-09 18:04:32 +010019 list["autoArchiveDuration"] = entry([before.autoArchiveDuration, after.autoArchiveDuration], `${humanizeDuration(before.autoArchiveDuration * 60 * 1000, { round: true })} -> ${humanizeDuration(after.autoArchiveDuration * 60 * 1000, { round: true })}`);
20 }
pineafane23c4ec2022-07-27 21:56:27 +010021 if (before.rateLimitPerUser !== after.rateLimitPerUser) {
pineafane625d782022-05-09 18:04:32 +010022 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}