blob: c42f77539391807f84546add36da8b7cfe2781b9 [file] [log] [blame]
PineaFan752af462022-12-31 21:59:38 +00001import type { NucleusClient } from "../utils/client.js";
TheCodedProfa16d1672023-01-18 18:58:34 -05002import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";
pineafan0f5cc782022-08-12 21:55:42 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "stickerUpdate";
pineafanda6e5342022-07-03 10:03:16 +01005
TheCodedProfa16d1672023-01-18 18:58:34 -05006export async function callback(client: NucleusClient, oldSticker: Sticker, newSticker: Sticker) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05007 const { getAuditLog, isLogging, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00008 if (!(await isLogging(newSticker.guild!.id, "stickerUpdate"))) return;
TheCodedProfa16d1672023-01-18 18:58:34 -05009 if (oldSticker.name === newSticker.name) return;
Skyler Greyda16adf2023-03-05 10:22:12 +000010 const auditLog = (await getAuditLog(newSticker.guild!, AuditLogEvent.StickerUpdate)).filter(
11 (entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id
12 )[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050013 if (auditLog.executor!.id === client.user!.id) return;
pineafanda6e5342022-07-03 10:03:16 +010014
pineafan63fc5e22022-08-04 22:04:10 +010015 const changes = {
TheCodedProfa16d1672023-01-18 18:58:34 -050016 stickerId: entry(newSticker.id, `\`${newSticker.id}\``),
17 edited: entry(newSticker.createdTimestamp, renderDelta(newSticker.createdTimestamp)),
Skyler Greyda16adf2023-03-05 10:22:12 +000018 editedBy: entry(
19 auditLog.executor!.id,
20 renderUser((await newSticker.guild!.members.fetch(auditLog.executor!.id)).user)
21 ),
TheCodedProfa16d1672023-01-18 18:58:34 -050022 name: entry([oldSticker.name, newSticker.name], `\`:${oldSticker.name}:\` -> \`:${newSticker.name}:\``)
pineafan63fc5e22022-08-04 22:04:10 +010023 };
24 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010025 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010026 type: "stickerUpdate",
27 displayName: "Sticker Edited",
28 calculateType: "stickerUpdate",
29 color: NucleusColors.yellow,
30 emoji: "GUILD.EMOJI.EDIT",
TheCodedProfa16d1672023-01-18 18:58:34 -050031 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010032 },
33 list: changes,
34 hidden: {
TheCodedProfa16d1672023-01-18 18:58:34 -050035 guild: newSticker.guild!.id
pineafanda6e5342022-07-03 10:03:16 +010036 }
pineafan63fc5e22022-08-04 22:04:10 +010037 };
38 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010039}