blob: b207f4f3434770474b8f88723e83f083ce63b5e4 [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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05008 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
9 if (!await isLogging(role.guild.id, "guildRoleUpdate")) return;
pineafan63fc5e22022-08-04 22:04:10 +010010 if (role.managed) return;
TheCodedProfa16d1672023-01-18 18:58:34 -050011 const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleDelete))
12 .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id)[0]!;
13 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010014 const data = {
15 meta: {
16 type: "roleDelete",
17 displayName: "Role Deleted",
18 calculateType: "guildRoleUpdate",
19 color: NucleusColors.red,
20 emoji: "GUILD.ROLES.DELETE",
TheCodedProfa16d1672023-01-18 18:58:34 -050021 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010022 },
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,
Skyler Grey11236ba2022-08-08 21:13:33 +010029 role.hoist ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010030 ),
31 mentionable: entry(
32 role.mentionable,
Skyler Grey11236ba2022-08-08 21:13:33 +010033 role.mentionable ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
Skyler Grey75ea9172022-08-06 10:22:23 +010034 ),
pineafan63fc5e22022-08-04 22:04:10 +010035 members: entry(role.members.size, `${role.members.size}`),
TheCodedProfa16d1672023-01-18 18:58:34 -050036 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010037 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050038 deleted: entry(Date.now(), renderDelta(Date.now()))
pineafan63fc5e22022-08-04 22:04:10 +010039 },
40 hidden: {
41 guild: role.guild.id
pineafan32767212022-03-14 21:27:39 +000042 }
pineafan63fc5e22022-08-04 22:04:10 +010043 };
44 log(data);
pineafan32767212022-03-14 21:27:39 +000045}