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(); |
| 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 = { |
| 14 | id: entry(nr.id, `\`${nr.id}\``), |
| 15 | role: entry(nr.id, renderRole(nr)), |
| 16 | edited: entry(nr.createdTimestamp, renderDelta(nr.createdTimestamp)), |
| 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` |
| 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 | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 31 | let data = { |
| 32 | meta:{ |
| 33 | type: 'roleUpdate', |
| 34 | displayName: 'Role Edited', |
| 35 | calculateType: 'guildRoleUpdate', |
| 36 | color: NucleusColors.yellow, |
| 37 | emoji: "GUILD.ROLES.EDIT", |
| 38 | timestamp: audit.createdTimestamp |
| 39 | }, |
| 40 | list: changes, |
| 41 | hidden: { |
| 42 | guild: nr.guild.id |
| 43 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 44 | } // TODO: show perms changed |
| 45 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 46 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 47 | } |