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 | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame^] | 6 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = role.client.logger |
| 7 | if (role.managed) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 8 | let auditLog = await getAuditLog(role.guild, 'ROLE_DELETE'); |
| 9 | let audit = auditLog.entries.filter(entry => entry.target.id == role.id).first(); |
| 10 | if (audit.executor.id == client.user.id) return; |
| 11 | let 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 | id: entry(role.id, `\`${role.id}\``), |
| 22 | role: entry(role.name, role.name), |
| 23 | color: entry(role.hexColor, `\`${role.hexColor}\``), |
| 24 | showInMemberList: entry(role.hoist, role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 25 | mentionable: entry(role.mentionable, role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 26 | members: entry(role.members.size, `${role.members.size}`), |
| 27 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 28 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)), |
| 29 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 30 | }, |
| 31 | hidden: { |
| 32 | guild: role.guild.id |
| 33 | } |
| 34 | } |
| 35 | log(data, client); |
| 36 | } |