blob: 7c6ca75b0e2ba9ffa79fb1ed9fd88947c33f11ef [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
2
3export const event = 'roleUpdate';
4
5export async function callback(client, or, nr) {
pineafane625d782022-05-09 18:04:32 +01006 try {
7 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger
pineafan32767212022-03-14 21:27:39 +00008
pineafane625d782022-05-09 18:04:32 +01009 let auditLog = await getAuditLog(nr.guild, 'ROLE_UPDATE');
10 let audit = auditLog.entries.first();
11 if (audit.executor.id == client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000012
pineafane625d782022-05-09 18:04:32 +010013 let changes = {
pineafanda6e5342022-07-03 10:03:16 +010014 roleId: entry(nr.id, `\`${nr.id}\``),
pineafane625d782022-05-09 18:04:32 +010015 role: entry(nr.id, renderRole(nr)),
pineafan73a7c4a2022-07-24 10:38:04 +010016 edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafane625d782022-05-09 18:04:32 +010017 editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user)),
18 }
19 let mentionable = ["", ""]
20 let hoist = ["", ""]
21 mentionable[0] = or.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
22 mentionable[1] = nr.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
23 hoist[0] = or.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
24 hoist[1] = nr.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
25 if (or.name != nr.name) changes["name"] = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
26 if (or.position != nr.position) changes["position"] = entry([or.position, nr.position], `${or.position} -> ${nr.position}`);
27 if (or.hoist != nr.hoist) changes["showInMemberList"] = entry([or.hoist, nr.hoist], `${hoist[0]} -> ${hoist[1]}`);
28 if (or.mentionable != nr.mentionable) changes["mentionable"] = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
29 if (or.hexColor != nr.hexColor) changes["color"] = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``);
pineafan32767212022-03-14 21:27:39 +000030
pineafan73a7c4a2022-07-24 10:38:04 +010031 if (Object.keys(changes).length == 4) return
32
pineafane625d782022-05-09 18:04:32 +010033 let data = {
34 meta:{
35 type: 'roleUpdate',
36 displayName: 'Role Edited',
37 calculateType: 'guildRoleUpdate',
38 color: NucleusColors.yellow,
39 emoji: "GUILD.ROLES.EDIT",
40 timestamp: audit.createdTimestamp
41 },
42 list: changes,
43 hidden: {
44 guild: nr.guild.id
45 }
pineafan73a7c4a2022-07-24 10:38:04 +010046 } // TODO: show perms changed (webpage)
pineafan4edb7762022-06-26 19:21:04 +010047 log(data);
pineafane625d782022-05-09 18:04:32 +010048 } catch {}
pineafan32767212022-03-14 21:27:39 +000049}