blob: f607cf4eb5ddc04f99f3e17f14774cae2e6affe4 [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) {
7 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
8 const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
9 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
10 if (!auditLog) return;
11 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010012 const data = {
13 meta: {
14 type: "emojiDelete",
15 displayName: "Emoji Deleted",
16 calculateType: "emojiUpdate",
17 color: NucleusColors.red,
18 emoji: "GUILD.EMOJI.DELETE",
PineaFane6ba7882023-01-18 20:41:16 +000019 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010020 },
21 list: {
22 emojiId: entry(emoji.id, `\`${emoji.id}\``),
23 emoji: entry(emoji.name, renderEmoji(emoji)),
PineaFane6ba7882023-01-18 20:41:16 +000024 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010025 created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
PineaFane6ba7882023-01-18 20:41:16 +000026 deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010027 },
28 hidden: {
29 guild: emoji.guild.id
pineafan32767212022-03-14 21:27:39 +000030 }
pineafan63fc5e22022-08-04 22:04:10 +010031 };
32 log(data);
pineafan32767212022-03-14 21:27:39 +000033}