blob: c4b488e5a3dfba4e2bea2653d3fc22b0da5ede53 [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import { AuditLogEvent } from 'discord.js';
2import type { NucleusClient } from "../utils/client.js";
3import 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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
8 if (!await isLogging(emoji.guild.id, "emojiUpdate")) return;
9 const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiDelete))
PineaFane6ba7882023-01-18 20:41:16 +000010 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
11 if (!auditLog) return;
12 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010013 const data = {
14 meta: {
15 type: "emojiDelete",
16 displayName: "Emoji Deleted",
17 calculateType: "emojiUpdate",
18 color: NucleusColors.red,
19 emoji: "GUILD.EMOJI.DELETE",
PineaFane6ba7882023-01-18 20:41:16 +000020 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010021 },
22 list: {
23 emojiId: entry(emoji.id, `\`${emoji.id}\``),
24 emoji: entry(emoji.name, renderEmoji(emoji)),
PineaFane6ba7882023-01-18 20:41:16 +000025 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
PineaFane6ba7882023-01-18 20:41:16 +000027 deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 hidden: {
30 guild: emoji.guild.id
pineafan32767212022-03-14 21:27:39 +000031 }
pineafan63fc5e22022-08-04 22:04:10 +010032 };
33 log(data);
pineafan32767212022-03-14 21:27:39 +000034}