pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 2 | // @ts-expect-error |
| 3 | import type { HaikuClient } from "jshaiku"; |
| 4 | import type { GuildAuditLogsEntry, Role } from "discord.js"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | export const event = "roleDelete"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 7 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 8 | export async function callback(client: HaikuClient, role: Role) { |
| 9 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | if (role.managed) return; |
| 11 | const auditLog = await getAuditLog(role.guild, "ROLE_DELETE"); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 12 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === role.id).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, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 29 | role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 30 | ), |
| 31 | mentionable: entry( |
| 32 | role.mentionable, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 33 | role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | members: entry(role.members.size, `${role.members.size}`), |
| 36 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 37 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)), |
| 38 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }, |
| 40 | hidden: { |
| 41 | guild: role.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 42 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | }; |
| 44 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 45 | } |