blob: 236a799a083b775384e7affd14600f5fdd254975 [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 = "emojiUpdate";
pineafan32767212022-03-14 21:27:39 +00005
PineaFane6ba7882023-01-18 20:41:16 +00006export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) {
TheCodedProf6ec331b2023-02-20 12:13:06 -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
Skyler Greyda16adf2023-03-05 10:22:12 +000010 const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiUpdate)).filter(
11 (entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id
12 )[0];
PineaFane6ba7882023-01-18 20:41:16 +000013 if (!auditLog) return;
14 if (auditLog.executor!.id === client.user!.id) return;
pineafan32767212022-03-14 21:27:39 +000015
pineafan63fc5e22022-08-04 22:04:10 +010016 const changes = {
PineaFane6ba7882023-01-18 20:41:16 +000017 emojiId: entry(newEmoji.id, `\`${newEmoji.id}\``),
18 emoji: entry(newEmoji.id, renderEmoji(newEmoji)),
19 edited: entry(newEmoji.createdTimestamp, renderDelta(newEmoji.createdTimestamp)),
Skyler Greyda16adf2023-03-05 10:22:12 +000020 editedBy: entry(
21 auditLog.executor!.id,
22 renderUser((await newEmoji.guild.members.fetch(auditLog.executor!.id)).user)
23 ),
PineaFane6ba7882023-01-18 20:41:16 +000024 name: entry([oldEmoji.name!, newEmoji.name!], `\`:${oldEmoji.name}:\` -> \`:${newEmoji.name}:\``)
pineafan63fc5e22022-08-04 22:04:10 +010025 };
26 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010027 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010028 type: "emojiUpdate",
29 displayName: "Emoji Edited",
30 calculateType: "emojiUpdate",
31 color: NucleusColors.yellow,
32 emoji: "GUILD.EMOJI.EDIT",
PineaFane6ba7882023-01-18 20:41:16 +000033 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010034 },
35 list: changes,
36 hidden: {
PineaFane6ba7882023-01-18 20:41:16 +000037 guild: newEmoji.guild.id
pineafane625d782022-05-09 18:04:32 +010038 }
pineafan63fc5e22022-08-04 22:04:10 +010039 };
Skyler Greyf4f21c42023-03-08 14:36:29 +000040 await log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010041}