blob: f41241b49ab6473a3dc196f52c18c801d10a599a [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) {
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;
TheCodedProfa16d1672023-01-18 18:58:34 -050010 const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleDelete))
11 .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id)[0]!;
12 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010013 const data = {
14 meta: {
15 type: "roleDelete",
16 displayName: "Role Deleted",
17 calculateType: "guildRoleUpdate",
18 color: NucleusColors.red,
19 emoji: "GUILD.ROLES.DELETE",
TheCodedProfa16d1672023-01-18 18:58:34 -050020 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010021 },
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}`),
TheCodedProfa16d1672023-01-18 18:58:34 -050035 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.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}