blob: 25e9c989f979be2024a70f463e0c736859f014b4 [file] [log] [blame]
PineaFan752af462022-12-31 21:59:38 +00001import type { NucleusClient } from "../utils/client.js";
pineafan0f5cc782022-08-12 21:55:42 +01002import type { GuildAuditLogsEntry, Role } from "discord.js";
3
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;
9 const auditLog = await getAuditLog(role.guild, "ROLE_CREATE");
pineafan0f5cc782022-08-12 21:55:42 +010010 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === role.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010011 if (audit.executor.id === client.user.id) return;
12 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)),
24 createdBy: entry(audit.executor.id, renderUser(audit.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}