Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { AuditLogEvent } from "discord.js"; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 2 | import type { NucleusClient } from "../utils/client.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 3 | import type { GuildEmoji, GuildAuditLogsEntry } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | export const event = "emojiUpdate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 6 | export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 7 | const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger; |
| 8 | if (!(await isLogging(newEmoji.guild.id, "emojiUpdate"))) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 9 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 10 | const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiUpdate)).filter( |
| 11 | (entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id |
| 12 | )[0]; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 13 | if (!auditLog) return; |
| 14 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 15 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | const changes = { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 17 | emojiId: entry(newEmoji.id, `\`${newEmoji.id}\``), |
| 18 | emoji: entry(newEmoji.id, renderEmoji(newEmoji)), |
| 19 | edited: entry(newEmoji.createdTimestamp, renderDelta(newEmoji.createdTimestamp)), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 20 | editedBy: entry( |
| 21 | auditLog.executor!.id, |
| 22 | renderUser((await newEmoji.guild.members.fetch(auditLog.executor!.id)).user) |
| 23 | ), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 24 | name: entry([oldEmoji.name!, newEmoji.name!], `\`:${oldEmoji.name}:\` -> \`:${newEmoji.name}:\``) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 25 | }; |
| 26 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 27 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | type: "emojiUpdate", |
| 29 | displayName: "Emoji Edited", |
| 30 | calculateType: "emojiUpdate", |
| 31 | color: NucleusColors.yellow, |
| 32 | emoji: "GUILD.EMOJI.EDIT", |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 33 | timestamp: auditLog.createdTimestamp |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | }, |
| 35 | list: changes, |
| 36 | hidden: { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 37 | guild: newEmoji.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 38 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 40 | await log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 41 | } |