pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 2 | |
| 3 | export const event = 'roleUpdate'; |
| 4 | |
| 5 | export async function callback(client, or, nr) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | try { |
| 7 | const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 8 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 9 | let auditLog = await getAuditLog(nr.guild, 'ROLE_UPDATE'); |
| 10 | let audit = auditLog.entries.first(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 11 | if (audit.executor.id === client.user.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 12 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 13 | let changes = { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 14 | roleId: entry(nr.id, `\`${nr.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 15 | role: entry(nr.id, renderRole(nr)), |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 16 | edited: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 17 | editedBy: entry(audit.executor.id, renderUser((await nr.guild.members.fetch(audit.executor.id)).user)), |
| 18 | } |
| 19 | let mentionable = ["", ""] |
| 20 | let hoist = ["", ""] |
| 21 | mentionable[0] = or.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
| 22 | mentionable[1] = nr.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
| 23 | hoist[0] = or.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
| 24 | hoist[1] = nr.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 25 | if (or.name !== nr.name) changes["name"] = entry([or.name, nr.name], `${or.name} -> ${nr.name}`); |
| 26 | if (or.position !== nr.position) 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]}`); |
| 28 | if (or.mentionable !== nr.mentionable) changes["mentionable"] = entry([or.mentionable, nr.mentionable], `${mentionable[0]} -> ${mentionable[1]}`); |
| 29 | if (or.hexColor !== nr.hexColor) changes["color"] = entry([or.hexColor, nr.hexColor], `\`${or.hexColor}\` -> \`${nr.hexColor}\``); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 30 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 31 | if (Object.keys(changes).length === 4) return |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 32 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 33 | let data = { |
| 34 | meta:{ |
| 35 | type: 'roleUpdate', |
| 36 | displayName: 'Role Edited', |
| 37 | calculateType: 'guildRoleUpdate', |
| 38 | color: NucleusColors.yellow, |
| 39 | emoji: "GUILD.ROLES.EDIT", |
| 40 | timestamp: audit.createdTimestamp |
| 41 | }, |
| 42 | list: changes, |
| 43 | hidden: { |
| 44 | guild: nr.guild.id |
| 45 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 46 | } // TODO: show perms changed (webpage) |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 47 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 48 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 49 | } |