blob: 4c895657738ed52b690f7346e1ffa276baf2dbfb [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
PineaFan752af462022-12-31 21:59:38 +00002import type { NucleusClient } from "../utils/client.js";
pineafan0f5cc782022-08-12 21:55:42 +01003import type { GuildAuditLogsEntry, Role } from "discord.js";
pineafan32767212022-03-14 21:27:39 +00004
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "roleDelete";
pineafan32767212022-03-14 21:27:39 +00006
PineaFan752af462022-12-31 21:59:38 +00007export async function callback(client: NucleusClient, role: Role) {
pineafan0f5cc782022-08-12 21:55:42 +01008 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 if (role.managed) return;
10 const auditLog = await getAuditLog(role.guild, "ROLE_DELETE");
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: "roleDelete",
16 displayName: "Role Deleted",
17 calculateType: "guildRoleUpdate",
18 color: NucleusColors.red,
19 emoji: "GUILD.ROLES.DELETE",
20 timestamp: audit.createdTimestamp
21 },
22 list: {
23 roleId: entry(role.id, `\`${role.id}\``),
24 role: entry(role.name, role.name),
25 color: entry(role.hexColor, `\`${role.hexColor}\``),
Skyler Grey75ea9172022-08-06 10:22:23 +010026 showInMemberList: entry(
27 role.hoist,
Skyler Grey11236ba2022-08-08 21:13:33 +010028 role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010029 ),
30 mentionable: entry(
31 role.mentionable,
Skyler Grey11236ba2022-08-08 21:13:33 +010032 role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010033 ),
pineafan63fc5e22022-08-04 22:04:10 +010034 members: entry(role.members.size, `${role.members.size}`),
35 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010036 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
37 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafan63fc5e22022-08-04 22:04:10 +010038 },
39 hidden: {
40 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000041 }
pineafan63fc5e22022-08-04 22:04:10 +010042 };
43 log(data);
pineafan32767212022-03-14 21:27:39 +000044}