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