blob: d253ce72f645cea58394a86ceb0e7f1761db46f8 [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) {
pineafan0f5cc782022-08-12 21:55:42 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01008 if (role.managed) return;
TheCodedProfa16d1672023-01-18 18:58:34 -05009 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;
pineafan63fc5e22022-08-04 22:04:10 +010012 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)),
TheCodedProfa16d1672023-01-18 18:58:34 -050024 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010025 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010026 },
27 hidden: {
28 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000029 }
pineafan63fc5e22022-08-04 22:04:10 +010030 };
31 log(data);
pineafan32767212022-03-14 21:27:39 +000032}