blob: c8a32b15801441972829f7c2dc01905be3e553b7 [file] [log] [blame]
PineaFan64486c42022-12-28 09:21:04 +00001import type { HaikuClient } from "../utils/haiku/index.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
pineafan0f5cc782022-08-12 21:55:42 +01006export async function callback(client: HaikuClient, role: Role) {
7 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}