blob: faf32374ea1c997f150c99fdc450d914e6708eac [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 = {
14 id: entry(nr.id, `\`${nr.id}\``),
15 role: entry(nr.id, renderRole(nr)),
16 edited: entry(nr.createdTimestamp, renderDelta(nr.createdTimestamp)),
17 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
pineafane625d782022-05-09 18:04:32 +010031 let data = {
32 meta:{
33 type: 'roleUpdate',
34 displayName: 'Role Edited',
35 calculateType: 'guildRoleUpdate',
36 color: NucleusColors.yellow,
37 emoji: "GUILD.ROLES.EDIT",
38 timestamp: audit.createdTimestamp
39 },
40 list: changes,
41 hidden: {
42 guild: nr.guild.id
43 }
44 }
45 log(data, client);
46 } catch {}
pineafan32767212022-03-14 21:27:39 +000047}