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 = "emojiDelete"; |
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, emoji: GuildEmoji) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 7 | const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 8 | if (!(await isLogging(emoji.guild.id, "emojiUpdate"))) return; |
| 9 | const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiDelete)).filter( |
| 10 | (entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id |
| 11 | )[0]; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 12 | if (!auditLog) return; |
| 13 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const data = { |
| 15 | meta: { |
| 16 | type: "emojiDelete", |
| 17 | displayName: "Emoji Deleted", |
| 18 | calculateType: "emojiUpdate", |
| 19 | color: NucleusColors.red, |
| 20 | emoji: "GUILD.EMOJI.DELETE", |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 21 | timestamp: auditLog.createdTimestamp |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | }, |
| 23 | list: { |
| 24 | emojiId: entry(emoji.id, `\`${emoji.id}\``), |
| 25 | emoji: entry(emoji.name, renderEmoji(emoji)), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 26 | deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 27 | created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 28 | deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | }, |
| 30 | hidden: { |
| 31 | guild: emoji.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 32 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 33 | }; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 34 | await log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 35 | } |