blob: 2cd3bc5013442247290ae980832bd3b69ba436a9 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2export const event = "inviteDelete";
pineafane625d782022-05-09 18:04:32 +01003
4export async function callback(client, invite) {
Skyler Grey11236ba2022-08-08 21:13:33 +01005 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01006 const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE");
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const audit = auditLog.entries.filter((entry) => entry.target.id === invite.id).first();
pineafan63fc5e22022-08-04 22:04:10 +01008 if (audit.executor.id === client.user.id) return;
9 const data = {
10 meta: {
11 type: "inviteDelete",
12 displayName: "Invite Deleted",
13 calculateType: "guildUpdate",
14 color: NucleusColors.red,
15 emoji: "INVITE.DELETE",
16 timestamp: new Date().getTime()
17 },
18 list: {
19 channel: entry(invite.channel.id, renderChannel(invite.channel)),
20 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010021 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
pineafan63fc5e22022-08-04 22:04:10 +010022 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010023 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafan63fc5e22022-08-04 22:04:10 +010024 },
25 hidden: {
26 guild: invite.guild.id
pineafane625d782022-05-09 18:04:32 +010027 }
pineafan63fc5e22022-08-04 22:04:10 +010028 };
29 log(data);
pineafane625d782022-05-09 18:04:32 +010030}