blob: ed01b71e8be01686cdf9ef6be6f515ea455f515d [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) {
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
pineafanda6e5342022-07-03 10:03:16 +01008
TheCodedProfa16d1672023-01-18 18:58:34 -05009 if (oldSticker.name === newSticker.name) return;
10 const auditLog = (await getAuditLog(newSticker.guild!, AuditLogEvent.StickerUpdate))
PineaFan638eb132023-01-19 10:41:22 +000011 .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id)[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050012 if (auditLog.executor!.id === client.user!.id) return;
pineafanda6e5342022-07-03 10:03:16 +010013
pineafan63fc5e22022-08-04 22:04:10 +010014 const changes = {
TheCodedProfa16d1672023-01-18 18:58:34 -050015 stickerId: entry(newSticker.id, `\`${newSticker.id}\``),
16 edited: entry(newSticker.createdTimestamp, renderDelta(newSticker.createdTimestamp)),
17 editedBy: entry(auditLog.executor!.id, renderUser((await newSticker.guild!.members.fetch(auditLog.executor!.id)).user)),
18 name: entry([oldSticker.name, newSticker.name], `\`:${oldSticker.name}:\` -> \`:${newSticker.name}:\``)
pineafan63fc5e22022-08-04 22:04:10 +010019 };
20 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010021 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010022 type: "stickerUpdate",
23 displayName: "Sticker Edited",
24 calculateType: "stickerUpdate",
25 color: NucleusColors.yellow,
26 emoji: "GUILD.EMOJI.EDIT",
TheCodedProfa16d1672023-01-18 18:58:34 -050027 timestamp: auditLog.createdTimestamp
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 list: changes,
30 hidden: {
TheCodedProfa16d1672023-01-18 18:58:34 -050031 guild: newSticker.guild!.id
pineafanda6e5342022-07-03 10:03:16 +010032 }
pineafan63fc5e22022-08-04 22:04:10 +010033 };
34 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010035}