blob: b07893aae1a406014f08ab1ccc63514ab6095823 [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");
pineafan0f5cc782022-08-12 21:55:42 +010012 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId).first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
14 const data = {
15 meta: {
16 type: "inviteDelete",
17 displayName: "Invite Deleted",
18 calculateType: "guildUpdate",
19 color: NucleusColors.red,
20 emoji: "INVITE.DELETE",
21 timestamp: new Date().getTime()
22 },
23 list: {
24 channel: entry(invite.channel.id, renderChannel(invite.channel)),
25 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
pineafan63fc5e22022-08-04 22:04:10 +010027 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
pineafan63fc5e22022-08-04 22:04:10 +010029 },
30 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010031 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010032 }
pineafan63fc5e22022-08-04 22:04:10 +010033 };
34 log(data);
pineafane625d782022-05-09 18:04:32 +010035}