PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 1 | import type { NucleusClient } from "../utils/client.js"; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 2 | import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 3 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | export const event = "stickerUpdate"; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 5 | |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 6 | export async function callback(client: NucleusClient, oldSticker: Sticker, newSticker: Sticker) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 7 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderDelta, renderUser } = client.logger; |
| 8 | if (!await isLogging(newSticker.guild!.id, "stickerUpdate")) return; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 9 | if (oldSticker.name === newSticker.name) return; |
| 10 | const auditLog = (await getAuditLog(newSticker.guild!, AuditLogEvent.StickerUpdate)) |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 11 | .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id)[0]!; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 12 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 13 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const changes = { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 15 | 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}:\``) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 19 | }; |
| 20 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | type: "stickerUpdate", |
| 23 | displayName: "Sticker Edited", |
| 24 | calculateType: "stickerUpdate", |
| 25 | color: NucleusColors.yellow, |
| 26 | emoji: "GUILD.EMOJI.EDIT", |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 27 | timestamp: auditLog.createdTimestamp |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | }, |
| 29 | list: changes, |
| 30 | hidden: { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 31 | guild: newSticker.guild!.id |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 32 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 33 | }; |
| 34 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | } |