blob: 34f66dc2ad3ef1971a9b5285436bfb6979f62ea3 [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 = "inviteCreate";
pineafane625d782022-05-09 18:04:32 +01007
PineaFan752af462022-12-31 21:59:38 +00008export async function callback(client: NucleusClient, invite: Invite) {
TheCodedProfa16d1672023-01-18 18:58:34 -05009 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;
11 if (!await isLogging(invite.guild.id, "guildUpdate")) return;
TheCodedProfa16d1672023-01-18 18:58:34 -050012 const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteCreate))
13 .filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!;
14 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010015 const data = {
16 meta: {
17 type: "inviteCreate",
18 displayName: "Invite Created",
19 calculateType: "guildUpdate",
20 color: NucleusColors.green,
21 emoji: "INVITE.CREATE",
TheCodedProf6ec331b2023-02-20 12:13:06 -050022 timestamp: invite.createdTimestamp ?? Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010023 },
24 list: {
TheCodedProfa16d1672023-01-18 18:58:34 -050025 channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)),
pineafan63fc5e22022-08-04 22:04:10 +010026 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"),
TheCodedProfa16d1672023-01-18 18:58:34 -050028 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
29 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp!))
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}