blob: 52822cb4d44510fd90bc0c11b0ddfe56b1398eb7 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { AuditLogEvent } from "discord.js";
PineaFane6ba7882023-01-18 20:41:16 +00002import type { NucleusClient } from "../utils/client.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00003import type { GuildEmoji, GuildAuditLogsEntry } from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "emojiDelete";
pineafan32767212022-03-14 21:27:39 +00005
PineaFane6ba7882023-01-18 20:41:16 +00006export async function callback(client: NucleusClient, emoji: GuildEmoji) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00008 if (!(await isLogging(emoji.guild.id, "emojiUpdate"))) return;
9 const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiDelete)).filter(
10 (entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id
11 )[0];
PineaFane6ba7882023-01-18 20:41:16 +000012 if (!auditLog) return;
13 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010014 const data = {
15 meta: {
16 type: "emojiDelete",
17 displayName: "Emoji Deleted",
18 calculateType: "emojiUpdate",
19 color: NucleusColors.red,
20 emoji: "GUILD.EMOJI.DELETE",
PineaFane6ba7882023-01-18 20:41:16 +000021 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010022 },
23 list: {
24 emojiId: entry(emoji.id, `\`${emoji.id}\``),
25 emoji: entry(emoji.name, renderEmoji(emoji)),
PineaFane6ba7882023-01-18 20:41:16 +000026 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
PineaFane6ba7882023-01-18 20:41:16 +000028 deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010029 },
30 hidden: {
31 guild: emoji.guild.id
pineafan32767212022-03-14 21:27:39 +000032 }
pineafan63fc5e22022-08-04 22:04:10 +010033 };
34 log(data);
pineafan32767212022-03-14 21:27:39 +000035}