pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 2 | |
| 3 | export const event = 'roleDelete' |
| 4 | |
| 5 | export async function callback(client, role) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | try { |
| 7 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = role.client.logger |
| 8 | if (role.managed) return; |
| 9 | let auditLog = await getAuditLog(role.guild, 'ROLE_DELETE'); |
| 10 | let audit = auditLog.entries.filter(entry => entry.target.id == role.id).first(); |
| 11 | if (audit.executor.id == client.user.id) return; |
| 12 | let data = { |
| 13 | meta: { |
| 14 | type: 'roleDelete', |
| 15 | displayName: 'Role Deleted', |
| 16 | calculateType: 'guildRoleUpdate', |
| 17 | color: NucleusColors.red, |
| 18 | emoji: "GUILD.ROLES.DELETE", |
| 19 | timestamp: audit.createdTimestamp, |
| 20 | }, |
| 21 | list: { |
| 22 | id: entry(role.id, `\`${role.id}\``), |
| 23 | role: entry(role.name, role.name), |
| 24 | color: entry(role.hexColor, `\`${role.hexColor}\``), |
| 25 | showInMemberList: entry(role.hoist, role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 26 | mentionable: entry(role.mentionable, role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 27 | members: entry(role.members.size, `${role.members.size}`), |
| 28 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 29 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)), |
| 30 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 31 | }, |
| 32 | hidden: { |
| 33 | guild: role.guild.id |
| 34 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 35 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 36 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 38 | } |