blob: 201dd4201ab5f99069c840f94afb92e3514a5295 [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) {
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;
pineafan32767212022-03-14 21:27:39 +00008
PineaFane6ba7882023-01-18 20:41:16 +00009 const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiCreate))
10 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];
11 if (!auditLog) return;
12 if (auditLog.executor!.id === client.user!.id) return;
pineafan32767212022-03-14 21:27:39 +000013
pineafan63fc5e22022-08-04 22:04:10 +010014 const changes = {
PineaFane6ba7882023-01-18 20:41:16 +000015 emojiId: entry(newEmoji.id, `\`${newEmoji.id}\``),
16 emoji: entry(newEmoji.id, renderEmoji(newEmoji)),
17 edited: entry(newEmoji.createdTimestamp, renderDelta(newEmoji.createdTimestamp)),
18 editedBy: entry(auditLog.executor!.id, renderUser((await newEmoji.guild.members.fetch(auditLog.executor!.id)).user)),
19 name: entry([oldEmoji.name!, newEmoji.name!], `\`:${oldEmoji.name}:\` -> \`:${newEmoji.name}:\``)
pineafan63fc5e22022-08-04 22:04:10 +010020 };
21 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010022 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010023 type: "emojiUpdate",
24 displayName: "Emoji Edited",
25 calculateType: "emojiUpdate",
26 color: NucleusColors.yellow,
27 emoji: "GUILD.EMOJI.EDIT",
PineaFane6ba7882023-01-18 20:41:16 +000028 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010029 },
30 list: changes,
31 hidden: {
PineaFane6ba7882023-01-18 20:41:16 +000032 guild: newEmoji.guild.id
pineafane625d782022-05-09 18:04:32 +010033 }
pineafan63fc5e22022-08-04 22:04:10 +010034 };
35 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010036}