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 = "roleDelete"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export async function callback(client, role) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 6 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = |
| 7 | role.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | if (role.managed) return; |
| 9 | const auditLog = await getAuditLog(role.guild, "ROLE_DELETE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 10 | const audit = auditLog.entries |
| 11 | .filter((entry) => entry.target.id === role.id) |
| 12 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | if (audit.executor.id === client.user.id) return; |
| 14 | const data = { |
| 15 | meta: { |
| 16 | type: "roleDelete", |
| 17 | displayName: "Role Deleted", |
| 18 | calculateType: "guildRoleUpdate", |
| 19 | color: NucleusColors.red, |
| 20 | emoji: "GUILD.ROLES.DELETE", |
| 21 | timestamp: audit.createdTimestamp |
| 22 | }, |
| 23 | list: { |
| 24 | roleId: entry(role.id, `\`${role.id}\``), |
| 25 | role: entry(role.name, role.name), |
| 26 | color: entry(role.hexColor, `\`${role.hexColor}\``), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 27 | showInMemberList: entry( |
| 28 | role.hoist, |
| 29 | role.hoist |
| 30 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 31 | : `${getEmojiByName("CONTROL.CROSS")} No` |
| 32 | ), |
| 33 | mentionable: entry( |
| 34 | role.mentionable, |
| 35 | role.mentionable |
| 36 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 37 | : `${getEmojiByName("CONTROL.CROSS")} No` |
| 38 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | members: entry(role.members.size, `${role.members.size}`), |
| 40 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 41 | created: entry( |
| 42 | role.createdTimestamp, |
| 43 | renderDelta(role.createdTimestamp) |
| 44 | ), |
| 45 | deleted: entry( |
| 46 | new Date().getTime(), |
| 47 | renderDelta(new Date().getTime()) |
| 48 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 49 | }, |
| 50 | hidden: { |
| 51 | guild: role.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 52 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 53 | }; |
| 54 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 55 | } |