blob: a7172422bf2be1ea23170d0941b8d6be92bf2b7b [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001export const event = "roleCreate";
pineafan32767212022-03-14 21:27:39 +00002
3export async function callback(client, role) {
pineafan63fc5e22022-08-04 22:04:10 +01004 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = role.client.logger;
5 if (role.managed) return;
6 const auditLog = await getAuditLog(role.guild, "ROLE_CREATE");
7 const audit = auditLog.entries.filter(entry => entry.target.id === role.id).first();
8 if (audit.executor.id === client.user.id) return;
9 const data = {
10 meta: {
11 type: "roleCreate",
12 displayName: "Role Created",
13 calculateType: "guildRoleUpdate",
14 color: NucleusColors.green,
15 emoji: "GUILD.ROLES.CREATE",
16 timestamp: role.createdTimestamp
17 },
18 list: {
19 roleId: entry(role.id, `\`${role.id}\``),
20 role: entry(role.name, renderRole(role)),
21 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
22 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp))
23 },
24 hidden: {
25 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000026 }
pineafan63fc5e22022-08-04 22:04:10 +010027 };
28 log(data);
pineafan32767212022-03-14 21:27:39 +000029}