blob: ea85b4d975f2c213786e9abcdf6582aca3877745 [file] [log] [blame]
PineaFan752af462022-12-31 21:59:38 +00001import type { NucleusClient } from "../utils/client.js";
TheCodedProfa16d1672023-01-18 18:58:34 -05002import { AuditLogEvent, Guild, GuildAuditLogsEntry, Role } from "discord.js";
pineafan0f5cc782022-08-12 21:55:42 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "roleCreate";
pineafan32767212022-03-14 21:27:39 +00005
PineaFan752af462022-12-31 21:59:38 +00006export async function callback(client: NucleusClient, role: Role) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05007 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00008 if (!(await isLogging(role.guild.id, "guildRoleUpdate"))) return;
pineafan63fc5e22022-08-04 22:04:10 +01009 if (role.managed) return;
Skyler Greyda16adf2023-03-05 10:22:12 +000010 const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleCreate)).filter(
11 (entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id
12 )[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050013 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010014 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)),
TheCodedProfa16d1672023-01-18 18:58:34 -050026 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 hidden: {
30 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000031 }
pineafan63fc5e22022-08-04 22:04:10 +010032 };
Skyler Greyf4f21c42023-03-08 14:36:29 +000033 await log(data);
pineafan32767212022-03-14 21:27:39 +000034}