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) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 7 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 8 | if (!(await isLogging(role.guild.id, "guildRoleUpdate"))) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | if (role.managed) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 10 | const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleCreate)).filter( |
| 11 | (entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id |
| 12 | )[0]!; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 13 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const data = { |
| 15 | meta: { |
| 16 | type: "roleCreate", |
| 17 | displayName: "Role Created", |
| 18 | calculateType: "guildRoleUpdate", |
| 19 | color: NucleusColors.green, |
| 20 | emoji: "GUILD.ROLES.CREATE", |
| 21 | timestamp: role.createdTimestamp |
| 22 | }, |
| 23 | list: { |
| 24 | roleId: entry(role.id, `\`${role.id}\``), |
| 25 | role: entry(role.name, renderRole(role)), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 26 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 27 | created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | }, |
| 29 | hidden: { |
| 30 | guild: role.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 31 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | }; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 33 | await log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 34 | } |