blob: 456af9066639419404a8bcee9c682c89dadf2811 [file] [log] [blame]
TheCodedProfa16d1672023-01-18 18:58:34 -05001import { AuditLogEvent, Guild, GuildAuditLogsEntry, GuildChannel, Invite } from "discord.js";
pineafan0f5cc782022-08-12 21:55:42 +01002// @ts-expect-error
pineafan63fc5e22022-08-04 22:04:10 +01003import humanizeDuration from "humanize-duration";
PineaFan752af462022-12-31 21:59:38 +00004import type { NucleusClient } from "../utils/client.js";
pineafan0f5cc782022-08-12 21:55:42 +01005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "inviteDelete";
pineafane625d782022-05-09 18:04:32 +01007
PineaFan752af462022-12-31 21:59:38 +00008export async function callback(client: NucleusClient, invite: Invite) {
TheCodedProfa16d1672023-01-18 18:58:34 -05009 if(!invite.guild) return; // This is a DM invite (not a guild invite
TheCodedProf6ec331b2023-02-20 12:13:06 -050010 const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
11 if (!await isLogging(invite.guild.id, "guildUpdate")) return;
TheCodedProfa16d1672023-01-18 18:58:34 -050012 const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteDelete))
13 .filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!;
14 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010015 const data = {
16 meta: {
17 type: "inviteDelete",
18 displayName: "Invite Deleted",
19 calculateType: "guildUpdate",
20 color: NucleusColors.red,
21 emoji: "INVITE.DELETE",
TheCodedProf6ec331b2023-02-20 12:13:06 -050022 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010023 },
24 list: {
TheCodedProfa16d1672023-01-18 18:58:34 -050025 channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)),
pineafan63fc5e22022-08-04 22:04:10 +010026 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
TheCodedProfa16d1672023-01-18 18:58:34 -050028 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050029 deleted: entry(Date.now(), renderDelta(Date.now()))
pineafan63fc5e22022-08-04 22:04:10 +010030 },
31 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010032 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010033 }
pineafan63fc5e22022-08-04 22:04:10 +010034 };
35 log(data);
pineafane625d782022-05-09 18:04:32 +010036}