blob: 375a693b4014b16c66810c0cc78e0c5011f89685 [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";
pineafan0f5cc782022-08-12 21:55:42 +01004// @ts-expect-error
5import type { HaikuClient } from "jshaiku";
6
pineafan63fc5e22022-08-04 22:04:10 +01007export const event = "inviteDelete";
pineafane625d782022-05-09 18:04:32 +01008
pineafan0f5cc782022-08-12 21:55:42 +01009export async function callback(client: HaikuClient, invite: Invite) {
10 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE");
Skyler Greyf21323a2022-08-13 23:58:22 +010012 const audit = auditLog.entries
13 .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
14 .first();
pineafan63fc5e22022-08-04 22:04:10 +010015 if (audit.executor.id === client.user.id) return;
16 const data = {
17 meta: {
18 type: "inviteDelete",
19 displayName: "Invite Deleted",
20 calculateType: "guildUpdate",
21 color: NucleusColors.red,
22 emoji: "INVITE.DELETE",
23 timestamp: new Date().getTime()
24 },
25 list: {
26 channel: entry(invite.channel.id, renderChannel(invite.channel)),
27 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"),
pineafan63fc5e22022-08-04 22:04:10 +010029 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010030 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
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}