blob: 98ff55889a7b1cb28980bff53d430e0698d076e0 [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 = "emojiUpdate";
pineafan32767212022-03-14 21:27:39 +00005
PineaFane6ba7882023-01-18 20:41:16 +00006export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
8 if (!(await isLogging(newEmoji.guild.id, "emojiUpdate"))) return;
pineafan32767212022-03-14 21:27:39 +00009
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050010 const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiUpdate))
PineaFane6ba7882023-01-18 20:41:16 +000011 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];
12 if (!auditLog) return;
13 if (auditLog.executor!.id === client.user!.id) return;
pineafan32767212022-03-14 21:27:39 +000014
pineafan63fc5e22022-08-04 22:04:10 +010015 const changes = {
PineaFane6ba7882023-01-18 20:41:16 +000016 emojiId: entry(newEmoji.id, `\`${newEmoji.id}\``),
17 emoji: entry(newEmoji.id, renderEmoji(newEmoji)),
18 edited: entry(newEmoji.createdTimestamp, renderDelta(newEmoji.createdTimestamp)),
19 editedBy: entry(auditLog.executor!.id, renderUser((await newEmoji.guild.members.fetch(auditLog.executor!.id)).user)),
20 name: entry([oldEmoji.name!, newEmoji.name!], `\`:${oldEmoji.name}:\` -> \`:${newEmoji.name}:\``)
pineafan63fc5e22022-08-04 22:04:10 +010021 };
22 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010023 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010024 type: "emojiUpdate",
25 displayName: "Emoji Edited",
26 calculateType: "emojiUpdate",
27 color: NucleusColors.yellow,
28 emoji: "GUILD.EMOJI.EDIT",
PineaFane6ba7882023-01-18 20:41:16 +000029 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010030 },
31 list: changes,
32 hidden: {
PineaFane6ba7882023-01-18 20:41:16 +000033 guild: newEmoji.guild.id
pineafane625d782022-05-09 18:04:32 +010034 }
pineafan63fc5e22022-08-04 22:04:10 +010035 };
36 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010037}