blob: be276e5471bb3d487078965885704281e0750cc3 [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 Grey75ea9172022-08-06 10:22:23 +01006 const {
7 getAuditLog,
8 log,
9 NucleusColors,
10 entry,
11 renderDelta,
12 renderUser,
13 renderRole
14 } = client.logger;
pineafan32767212022-03-14 21:27:39 +000015
pineafan63fc5e22022-08-04 22:04:10 +010016 const auditLog = await getAuditLog(nr.guild, "ROLE_UPDATE");
17 const audit = auditLog.entries.first();
18 if (audit.executor.id === client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000019
pineafan63fc5e22022-08-04 22:04:10 +010020 const changes = {
21 roleId: entry(nr.id, `\`${nr.id}\``),
22 role: entry(nr.id, renderRole(nr)),
23 edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
Skyler Grey75ea9172022-08-06 10:22:23 +010024 editedBy: entry(
25 audit.executor.id,
26 renderUser((await nr.guild.members.fetch(audit.executor.id)).user)
27 )
pineafan63fc5e22022-08-04 22:04:10 +010028 };
29 const mentionable = ["", ""];
30 const hoist = ["", ""];
Skyler Grey75ea9172022-08-06 10:22:23 +010031 mentionable[0] = or.mentionable
32 ? `${getEmojiByName("CONTROL.TICK")} Yes`
33 : `${getEmojiByName("CONTROL.CROSS")} No`;
34 mentionable[1] = nr.mentionable
35 ? `${getEmojiByName("CONTROL.TICK")} Yes`
36 : `${getEmojiByName("CONTROL.CROSS")} No`;
37 hoist[0] = or.hoist
38 ? `${getEmojiByName("CONTROL.TICK")} Yes`
39 : `${getEmojiByName("CONTROL.CROSS")} No`;
40 hoist[1] = nr.hoist
41 ? `${getEmojiByName("CONTROL.TICK")} Yes`
42 : `${getEmojiByName("CONTROL.CROSS")} No`;
43 if (or.name !== nr.name)
44 changes.name = entry([or.name, nr.name], `${or.name} -> ${nr.name}`);
45 if (or.position !== nr.position)
46 changes.position = entry(
47 [or.position, nr.position],
48 `${or.position} -> ${nr.position}`
49 );
50 if (or.hoist !== nr.hoist)
51 changes.showInMemberList = entry(
52 [or.hoist, nr.hoist],
53 `${hoist[0]} -> ${hoist[1]}`
54 );
55 if (or.mentionable !== nr.mentionable)
56 changes.mentionable = entry(
57 [or.mentionable, nr.mentionable],
58 `${mentionable[0]} -> ${mentionable[1]}`
59 );
60 if (or.hexColor !== nr.hexColor)
61 changes.color = entry(
62 [or.hexColor, nr.hexColor],
63 `\`${or.hexColor}\` -> \`${nr.hexColor}\``
64 );
pineafan63fc5e22022-08-04 22:04:10 +010065
66 if (Object.keys(changes).length === 4) return;
67
68 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010069 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010070 type: "roleUpdate",
71 displayName: "Role Edited",
72 calculateType: "guildRoleUpdate",
73 color: NucleusColors.yellow,
74 emoji: "GUILD.ROLES.EDIT",
75 timestamp: audit.createdTimestamp
76 },
77 list: changes,
78 hidden: {
79 guild: nr.guild.id
pineafane625d782022-05-09 18:04:32 +010080 }
pineafan63fc5e22022-08-04 22:04:10 +010081 }; // TODO: show perms changed (webpage)
82 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010083}