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) { |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 7 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger; |
| 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; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 10 | const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleCreate)) |
| 11 | .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id)[0]!; |
| 12 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 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)), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 25 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.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 | } |