blob: 185ea8e113c17baaa0c72f74347003fdbfc5b74c [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
2
pineafan63fc5e22022-08-04 22:04:10 +01003export const event = "roleDelete";
pineafan32767212022-03-14 21:27:39 +00004
5export async function callback(client, role) {
Skyler Grey75ea9172022-08-06 10:22:23 +01006 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
7 role.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01008 if (role.managed) return;
9 const auditLog = await getAuditLog(role.guild, "ROLE_DELETE");
Skyler Grey75ea9172022-08-06 10:22:23 +010010 const audit = auditLog.entries
11 .filter((entry) => entry.target.id === role.id)
12 .first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
14 const data = {
15 meta: {
16 type: "roleDelete",
17 displayName: "Role Deleted",
18 calculateType: "guildRoleUpdate",
19 color: NucleusColors.red,
20 emoji: "GUILD.ROLES.DELETE",
21 timestamp: audit.createdTimestamp
22 },
23 list: {
24 roleId: entry(role.id, `\`${role.id}\``),
25 role: entry(role.name, role.name),
26 color: entry(role.hexColor, `\`${role.hexColor}\``),
Skyler Grey75ea9172022-08-06 10:22:23 +010027 showInMemberList: entry(
28 role.hoist,
29 role.hoist
30 ? `${getEmojiByName("CONTROL.TICK")} Yes`
31 : `${getEmojiByName("CONTROL.CROSS")} No`
32 ),
33 mentionable: entry(
34 role.mentionable,
35 role.mentionable
36 ? `${getEmojiByName("CONTROL.TICK")} Yes`
37 : `${getEmojiByName("CONTROL.CROSS")} No`
38 ),
pineafan63fc5e22022-08-04 22:04:10 +010039 members: entry(role.members.size, `${role.members.size}`),
40 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010041 created: entry(
42 role.createdTimestamp,
43 renderDelta(role.createdTimestamp)
44 ),
45 deleted: entry(
46 new Date().getTime(),
47 renderDelta(new Date().getTime())
48 )
pineafan63fc5e22022-08-04 22:04:10 +010049 },
50 hidden: {
51 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000052 }
pineafan63fc5e22022-08-04 22:04:10 +010053 };
54 log(data);
pineafan32767212022-03-14 21:27:39 +000055}