blob: e74ad156201166e954bfa62a07e3772fd9de4567 [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001import type { GuildAuditLogsEntry, Invite } from "discord.js";
2// @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) {
pineafan0f5cc782022-08-12 21:55:42 +01009 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE");
Skyler Greyf21323a2022-08-13 23:58:22 +010011 const audit = auditLog.entries
12 .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
13 .first();
pineafan63fc5e22022-08-04 22:04:10 +010014 if (audit.executor.id === client.user.id) return;
15 const data = {
16 meta: {
17 type: "inviteDelete",
18 displayName: "Invite Deleted",
19 calculateType: "guildUpdate",
20 color: NucleusColors.red,
21 emoji: "INVITE.DELETE",
22 timestamp: new Date().getTime()
23 },
24 list: {
25 channel: entry(invite.channel.id, renderChannel(invite.channel)),
26 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"),
pineafan63fc5e22022-08-04 22:04:10 +010028 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010029 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
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}