blob: 81285c72e64da86c0062a442effbc16f0108e3ba [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) {
Skyler Greyda16adf2023-03-05 10:22:12 +00009 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;
Skyler Greyda16adf2023-03-05 10:22:12 +000011 if (!(await isLogging(invite.guild.id, "guildUpdate"))) return;
12 const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteDelete)).filter(
13 (entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code
14 )[0]!;
TheCodedProfa16d1672023-01-18 18:58:34 -050015 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010016 const data = {
17 meta: {
18 type: "inviteDelete",
19 displayName: "Invite Deleted",
20 calculateType: "guildUpdate",
21 color: NucleusColors.red,
22 emoji: "INVITE.DELETE",
TheCodedProf6ec331b2023-02-20 12:13:06 -050023 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010024 },
25 list: {
TheCodedProfa16d1672023-01-18 18:58:34 -050026 channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)),
pineafan63fc5e22022-08-04 22:04:10 +010027 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
TheCodedProfa16d1672023-01-18 18:58:34 -050029 deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050030 deleted: entry(Date.now(), renderDelta(Date.now()))
pineafan63fc5e22022-08-04 22:04:10 +010031 },
32 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010033 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010034 }
pineafan63fc5e22022-08-04 22:04:10 +010035 };
36 log(data);
pineafane625d782022-05-09 18:04:32 +010037}