blob: 28afe0eff572072b392f985b4eff05f96883e394 [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) {
6 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger
7
8 let auditLog = await getAuditLog(nr.guild, 'ROLE_UPDATE');
9 let audit = auditLog.entries.first();
10 if (audit.executor.id == client.user.id) return;
11
12 let changes = {
13 id: entry(nr.id, `\`${nr.id}\``),
14 role: entry(nr.id, renderRole(nr)),
15 edited: entry(nr.createdTimestamp, renderDelta(nr.createdTimestamp)),
16 editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user)),
17 }
18 let mentionable = ["", ""]
19 let hoist = ["", ""]
20 mentionable[0] = or.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
21 mentionable[1] = nr.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
22 hoist[0] = or.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
23 hoist[1] = nr.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
24 if (or.name != nr.name) changes["name"] = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
25 if (or.position != nr.position) changes["position"] = entry([or.position, nr.position], `${or.position} -> ${nr.position}`);
26 if (or.hoist != nr.hoist) changes["showInMemberList"] = entry([or.hoist, nr.hoist], `${hoist[0]} -> ${hoist[1]}`);
27 if (or.mentionable != nr.mentionable) changes["mentionable"] = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
28 if (or.hexColor != nr.hexColor) changes["color"] = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``);
29
30 let data = {
31 meta:{
32 type: 'roleUpdate',
33 displayName: 'Role Edited',
34 calculateType: 'guildRoleUpdate',
35 color: NucleusColors.yellow,
36 emoji: "GUILD.ROLES.EDIT",
37 timestamp: audit.createdTimestamp
38 },
39 list: changes,
40 hidden: {
41 guild: nr.guild.id
42 }
43 }
44 log(data, client);
45}