blob: 4807e7dcedf1f37050713223843ccb15d4bc0800 [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 Grey11236ba2022-08-08 21:13:33 +01006 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = role.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01007 if (role.managed) return;
8 const auditLog = await getAuditLog(role.guild, "ROLE_DELETE");
Skyler Grey11236ba2022-08-08 21:13:33 +01009 const audit = auditLog.entries.filter((entry) => entry.target.id === role.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010010 if (audit.executor.id === client.user.id) return;
11 const data = {
12 meta: {
13 type: "roleDelete",
14 displayName: "Role Deleted",
15 calculateType: "guildRoleUpdate",
16 color: NucleusColors.red,
17 emoji: "GUILD.ROLES.DELETE",
18 timestamp: audit.createdTimestamp
19 },
20 list: {
21 roleId: entry(role.id, `\`${role.id}\``),
22 role: entry(role.name, role.name),
23 color: entry(role.hexColor, `\`${role.hexColor}\``),
Skyler Grey75ea9172022-08-06 10:22:23 +010024 showInMemberList: entry(
25 role.hoist,
Skyler Grey11236ba2022-08-08 21:13:33 +010026 role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010027 ),
28 mentionable: entry(
29 role.mentionable,
Skyler Grey11236ba2022-08-08 21:13:33 +010030 role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010031 ),
pineafan63fc5e22022-08-04 22:04:10 +010032 members: entry(role.members.size, `${role.members.size}`),
33 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010034 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
35 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafan63fc5e22022-08-04 22:04:10 +010036 },
37 hidden: {
38 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000039 }
pineafan63fc5e22022-08-04 22:04:10 +010040 };
41 log(data);
pineafan32767212022-03-14 21:27:39 +000042}