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