blob: 1802518750c1204efb1bcd310e55e27d7cfbb8c5 [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";
TheCodedProfa16d1672023-01-18 18:58:34 -05003import { AuditLogEvent, Guild, 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) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05008 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00009 if (!(await isLogging(role.guild.id, "guildRoleUpdate"))) return;
pineafan63fc5e22022-08-04 22:04:10 +010010 if (role.managed) return;
Skyler Greyda16adf2023-03-05 10:22:12 +000011 const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleDelete)).filter(
12 (entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id
13 )[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050014 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010015 const data = {
16 meta: {
17 type: "roleDelete",
18 displayName: "Role Deleted",
19 calculateType: "guildRoleUpdate",
20 color: NucleusColors.red,
21 emoji: "GUILD.ROLES.DELETE",
TheCodedProfa16d1672023-01-18 18:58:34 -050022 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010023 },
24 list: {
25 roleId: entry(role.id, `\`${role.id}\``),
26 role: entry(role.name, role.name),
27 color: entry(role.hexColor, `\`${role.hexColor}\``),
Skyler Grey75ea9172022-08-06 10:22:23 +010028 showInMemberList: entry(
29 role.hoist,
Skyler Grey11236ba2022-08-08 21:13:33 +010030 role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010031 ),
32 mentionable: entry(
33 role.mentionable,
Skyler Grey11236ba2022-08-08 21:13:33 +010034 role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010035 ),
pineafan63fc5e22022-08-04 22:04:10 +010036 members: entry(role.members.size, `${role.members.size}`),
TheCodedProfa16d1672023-01-18 18:58:34 -050037 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010038 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050039 deleted: entry(Date.now(), renderDelta(Date.now()))
pineafan63fc5e22022-08-04 22:04:10 +010040 },
41 hidden: {
42 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000043 }
pineafan63fc5e22022-08-04 22:04:10 +010044 };
Skyler Greyf4f21c42023-03-08 14:36:29 +000045 await log(data);
pineafan32767212022-03-14 21:27:39 +000046}