pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 1 | // @ts-expect-error |
| 2 | import type { HaikuClient } from "jshaiku"; |
| 3 | import type { GuildAuditLogsEntry, Role } from "discord.js"; |
| 4 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | export const event = "roleCreate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 6 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 7 | export async function callback(client: HaikuClient, role: Role) { |
| 8 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | if (role.managed) return; |
| 10 | const auditLog = await getAuditLog(role.guild, "ROLE_CREATE"); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 11 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === role.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | if (audit.executor.id === client.user.id) return; |
| 13 | const data = { |
| 14 | meta: { |
| 15 | type: "roleCreate", |
| 16 | displayName: "Role Created", |
| 17 | calculateType: "guildRoleUpdate", |
| 18 | color: NucleusColors.green, |
| 19 | emoji: "GUILD.ROLES.CREATE", |
| 20 | timestamp: role.createdTimestamp |
| 21 | }, |
| 22 | list: { |
| 23 | roleId: entry(role.id, `\`${role.id}\``), |
| 24 | role: entry(role.name, renderRole(role)), |
| 25 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 26 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 27 | }, |
| 28 | hidden: { |
| 29 | guild: role.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 30 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | }; |
| 32 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 33 | } |