blob: 96f790991be1ca9045b6c6944aaad8a572e09549 [file] [log] [blame]
Skyler Greyda16adf2023-03-05 10:22:12 +00001import { AuditLogEvent } from "discord.js";
PineaFane6ba7882023-01-18 20:41:16 +00002import type { NucleusClient } from "../utils/client.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00003import type { GuildEmoji, GuildAuditLogsEntry } from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "emojiCreate";
pineafan32767212022-03-14 21:27:39 +00005
PineaFane6ba7882023-01-18 20:41:16 +00006export async function callback(client: NucleusClient, emoji: GuildEmoji) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00008 if (!(await isLogging(emoji.guild.id, "emojiUpdate"))) return;
9 const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate)).filter(
10 (entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id
11 )[0];
PineaFane6ba7882023-01-18 20:41:16 +000012 if (!auditLog) return;
13 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010014 const data = {
15 meta: {
16 type: "emojiCreate",
17 displayName: "Emoji Created",
18 calculateType: "emojiUpdate",
19 color: NucleusColors.green,
20 emoji: "GUILD.EMOJI.CREATE",
21 timestamp: emoji.createdTimestamp
22 },
23 list: {
24 emojiId: entry(emoji.id, `\`${emoji.id}\``),
25 emoji: entry(emoji.name, renderEmoji(emoji)),
PineaFane6ba7882023-01-18 20:41:16 +000026 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 hidden: {
30 guild: emoji.guild.id
pineafan32767212022-03-14 21:27:39 +000031 }
pineafan63fc5e22022-08-04 22:04:10 +010032 };
33 log(data);
pineafan32767212022-03-14 21:27:39 +000034}