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