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