blob: 53bbdee6f4c39636e0513a170c0d90301d4f742a [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) {
Skyler Grey11236ba2022-08-08 21:13:33 +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())),
Skyler Grey11236ba2022-08-08 21:13:33 +010016 editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user))
pineafan63fc5e22022-08-04 22:04:10 +010017 };
18 const mentionable = ["", ""];
19 const hoist = ["", ""];
Skyler Grey11236ba2022-08-08 21:13:33 +010020 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}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010025 if (or.position !== nr.position)
Skyler Grey11236ba2022-08-08 21:13:33 +010026 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]}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010028 if (or.mentionable !== nr.mentionable)
Skyler Grey11236ba2022-08-08 21:13:33 +010029 changes.mentionable = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010030 if (or.hexColor !== nr.hexColor)
Skyler Grey11236ba2022-08-08 21:13:33 +010031 changes.color = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``);
pineafan63fc5e22022-08-04 22:04:10 +010032
33 if (Object.keys(changes).length === 4) return;
34
35 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010036 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010037 type: "roleUpdate",
38 displayName: "Role Edited",
39 calculateType: "guildRoleUpdate",
40 color: NucleusColors.yellow,
41 emoji: "GUILD.ROLES.EDIT",
42 timestamp: audit.createdTimestamp
43 },
44 list: changes,
45 hidden: {
46 guild: nr.guild.id
pineafane625d782022-05-09 18:04:32 +010047 }
pineafan63fc5e22022-08-04 22:04:10 +010048 }; // TODO: show perms changed (webpage)
49 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010050}