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) { |
| 6 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = role.client.logger |
| 7 | let auditLog = await getAuditLog(role.guild, 'ROLE_DELETE'); |
| 8 | let audit = auditLog.entries.filter(entry => entry.target.id == role.id).first(); |
| 9 | if (audit.executor.id == client.user.id) return; |
| 10 | let data = { |
| 11 | meta: { |
| 12 | type: 'roleDelete', |
| 13 | displayName: 'Role Deleted', |
| 14 | calculateType: 'guildRoleUpdate', |
| 15 | color: NucleusColors.red, |
| 16 | emoji: "GUILD.ROLES.DELETE", |
| 17 | timestamp: audit.createdTimestamp, |
| 18 | }, |
| 19 | list: { |
| 20 | id: entry(role.id, `\`${role.id}\``), |
| 21 | role: entry(role.name, role.name), |
| 22 | color: entry(role.hexColor, `\`${role.hexColor}\``), |
| 23 | showInMemberList: entry(role.hoist, role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 24 | mentionable: entry(role.mentionable, role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`), |
| 25 | members: entry(role.members.size, `${role.members.size}`), |
| 26 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 27 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)), |
| 28 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 29 | }, |
| 30 | hidden: { |
| 31 | guild: role.guild.id |
| 32 | } |
| 33 | } |
| 34 | log(data, client); |
| 35 | } |