blob: b0cb0f70513eebe5ddc3788edc7722522b309a5c [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
2
3export const event = 'roleDelete'
4
5export async function callback(client, role) {
pineafane625d782022-05-09 18:04:32 +01006 try {
7 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = role.client.logger
8 if (role.managed) return;
9 let auditLog = await getAuditLog(role.guild, 'ROLE_DELETE');
10 let audit = auditLog.entries.filter(entry => entry.target.id == role.id).first();
11 if (audit.executor.id == client.user.id) return;
12 let data = {
13 meta: {
14 type: 'roleDelete',
15 displayName: 'Role Deleted',
16 calculateType: 'guildRoleUpdate',
17 color: NucleusColors.red,
18 emoji: "GUILD.ROLES.DELETE",
19 timestamp: audit.createdTimestamp,
20 },
21 list: {
22 id: entry(role.id, `\`${role.id}\``),
23 role: entry(role.name, role.name),
24 color: entry(role.hexColor, `\`${role.hexColor}\``),
25 showInMemberList: entry(role.hoist, role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`),
26 mentionable: entry(role.mentionable, role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`),
27 members: entry(role.members.size, `${role.members.size}`),
28 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
29 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
30 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
31 },
32 hidden: {
33 guild: role.guild.id
34 }
pineafan32767212022-03-14 21:27:39 +000035 }
pineafan4edb7762022-06-26 19:21:04 +010036 log(data);
pineafane625d782022-05-09 18:04:32 +010037 } catch {}
pineafan32767212022-03-14 21:27:39 +000038}