blob: 263029506eee63e3c1e5ca3d717a9c7ada64660e [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import { AuditLogEvent } from 'discord.js';
2import type { NucleusClient } from "../utils/client.js";
3import 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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
8 if (!await isLogging(emoji.guild.id, "emojiUpdate")) return;
PineaFane6ba7882023-01-18 20:41:16 +00009 const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050010 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
PineaFane6ba7882023-01-18 20:41:16 +000011 if (!auditLog) return;
12 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010013 const data = {
14 meta: {
15 type: "emojiCreate",
16 displayName: "Emoji Created",
17 calculateType: "emojiUpdate",
18 color: NucleusColors.green,
19 emoji: "GUILD.EMOJI.CREATE",
20 timestamp: emoji.createdTimestamp
21 },
22 list: {
23 emojiId: entry(emoji.id, `\`${emoji.id}\``),
24 emoji: entry(emoji.name, renderEmoji(emoji)),
PineaFane6ba7882023-01-18 20:41:16 +000025 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010027 },
28 hidden: {
29 guild: emoji.guild.id
pineafan32767212022-03-14 21:27:39 +000030 }
pineafan63fc5e22022-08-04 22:04:10 +010031 };
32 log(data);
pineafan32767212022-03-14 21:27:39 +000033}
PineaFane6ba7882023-01-18 20:41:16 +000034