blob: c51a9b39719bfc33af270b09b8ce5c8e75119aa7 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
2
pineafan63fc5e22022-08-04 22:04:10 +01003export const event = "roleUpdate";
pineafan32767212022-03-14 21:27:39 +00004
5export async function callback(client, or, nr) {
pineafan63fc5e22022-08-04 22:04:10 +01006 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger;
pineafan32767212022-03-14 21:27:39 +00007
pineafan63fc5e22022-08-04 22:04:10 +01008 const auditLog = await getAuditLog(nr.guild, "ROLE_UPDATE");
9 const audit = auditLog.entries.first();
10 if (audit.executor.id === client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000011
pineafan63fc5e22022-08-04 22:04:10 +010012 const changes = {
13 roleId: entry(nr.id, `\`${nr.id}\``),
14 role: entry(nr.id, renderRole(nr)),
15 edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
16 editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user))
17 };
18 const mentionable = ["", ""];
19 const 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 if (Object.keys(changes).length === 4) return;
31
32 const data = {
33 meta:{
34 type: "roleUpdate",
35 displayName: "Role Edited",
36 calculateType: "guildRoleUpdate",
37 color: NucleusColors.yellow,
38 emoji: "GUILD.ROLES.EDIT",
39 timestamp: audit.createdTimestamp
40 },
41 list: changes,
42 hidden: {
43 guild: nr.guild.id
pineafane625d782022-05-09 18:04:32 +010044 }
pineafan63fc5e22022-08-04 22:04:10 +010045 }; // TODO: show perms changed (webpage)
46 log(data);
pineafan32767212022-03-14 21:27:39 +000047}