blob: e7a0a5c52889905e3b0a9a814dbe3de92112ae05 [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001// @ts-expect-error
2import type { HaikuClient } from "jshaiku";
3import type { GuildAuditLogsEntry, Role } from "discord.js";
4
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "roleCreate";
pineafan32767212022-03-14 21:27:39 +00006
pineafan0f5cc782022-08-12 21:55:42 +01007export async function callback(client: HaikuClient, role: Role) {
8 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 if (role.managed) return;
10 const auditLog = await getAuditLog(role.guild, "ROLE_CREATE");
pineafan0f5cc782022-08-12 21:55:42 +010011 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === role.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010012 if (audit.executor.id === client.user.id) return;
13 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)),
25 createdBy: entry(audit.executor.id, renderUser(audit.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}