pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 2 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | export const event = "roleUpdate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export async function callback(client, or, nr) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 6 | const { |
| 7 | getAuditLog, |
| 8 | log, |
| 9 | NucleusColors, |
| 10 | entry, |
| 11 | renderDelta, |
| 12 | renderUser, |
| 13 | renderRole |
| 14 | } = client.logger; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 15 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | const auditLog = await getAuditLog(nr.guild, "ROLE_UPDATE"); |
| 17 | const audit = auditLog.entries.first(); |
| 18 | if (audit.executor.id === client.user.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 19 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 24 | editedBy: entry( |
| 25 | audit.executor.id, |
| 26 | renderUser((await nr.guild.members.fetch(audit.executor.id)).user) |
| 27 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | }; |
| 29 | const mentionable = ["", ""]; |
| 30 | const hoist = ["", ""]; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 31 | 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 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 65 | |
| 66 | if (Object.keys(changes).length === 4) return; |
| 67 | |
| 68 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 69 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 70 | 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 80 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 81 | }; // TODO: show perms changed (webpage) |
| 82 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 83 | } |