blob: be385f016e868a279c1b9f3332b8ecd31f01be63 [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;
8 if (!await isLogging(role.guild.id, "guildRoleUpdate")) return;
pineafan63fc5e22022-08-04 22:04:10 +01009 if (role.managed) return;
TheCodedProfa16d1672023-01-18 18:58:34 -050010 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;
pineafan63fc5e22022-08-04 22:04:10 +010013 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)),
TheCodedProfa16d1672023-01-18 18:58:34 -050025 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010027 },
28 hidden: {
29 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000030 }
pineafan63fc5e22022-08-04 22:04:10 +010031 };
32 log(data);
pineafan32767212022-03-14 21:27:39 +000033}