blob: 348f211c82a49551165f8ea9a59137a477d1d890 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import getEmojiByName from "../utils/getEmojiByName.js";
pineafan0f5cc782022-08-12 21:55:42 +01002// @ts-expect-error
3import type { HaikuClient } from "jshaiku";
4import type { GuildAuditLogsEntry, Role } from "discord.js";
pineafan32767212022-03-14 21:27:39 +00005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "roleDelete";
pineafan32767212022-03-14 21:27:39 +00007
pineafan0f5cc782022-08-12 21:55:42 +01008export async function callback(client: HaikuClient, role: Role) {
9 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 if (role.managed) return;
11 const auditLog = await getAuditLog(role.guild, "ROLE_DELETE");
pineafan0f5cc782022-08-12 21:55:42 +010012 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === role.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
14 const data = {
15 meta: {
16 type: "roleDelete",
17 displayName: "Role Deleted",
18 calculateType: "guildRoleUpdate",
19 color: NucleusColors.red,
20 emoji: "GUILD.ROLES.DELETE",
21 timestamp: audit.createdTimestamp
22 },
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}`),
36 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010037 created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
38 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
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}