blob: 7b23bb28871634c48490c0e97450bae97fd32fc1 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2export const event = "inviteCreate";
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_CREATE");
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: "inviteCreate",
12 displayName: "Invite Created",
13 calculateType: "guildUpdate",
14 color: NucleusColors.green,
15 emoji: "INVITE.CREATE",
16 timestamp: invite.createdTimestamp
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 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010023 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
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}