blob: 5461307c02672b5b0cd8ca77cd2cb45166642b87 [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 Grey75ea9172022-08-06 10:22:23 +01005 const {
6 getAuditLog,
7 log,
8 NucleusColors,
9 entry,
10 renderUser,
11 renderDelta,
12 renderChannel
13 } = invite.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010014 const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010015 const audit = auditLog.entries
16 .filter((entry) => entry.target.id === invite.id)
17 .first();
pineafan63fc5e22022-08-04 22:04:10 +010018 if (audit.executor.id === client.user.id) return;
19 const data = {
20 meta: {
21 type: "inviteCreate",
22 displayName: "Invite Created",
23 calculateType: "guildUpdate",
24 color: NucleusColors.green,
25 emoji: "INVITE.CREATE",
26 timestamp: invite.createdTimestamp
27 },
28 list: {
29 channel: entry(invite.channel.id, renderChannel(invite.channel)),
30 link: entry(invite.url, invite.url),
Skyler Grey75ea9172022-08-06 10:22:23 +010031 expires: entry(
32 invite.maxAge,
33 invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"
34 ),
pineafan63fc5e22022-08-04 22:04:10 +010035 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010036 created: entry(
37 invite.createdTimestamp,
38 renderDelta(invite.createdTimestamp)
39 )
pineafan63fc5e22022-08-04 22:04:10 +010040 },
41 hidden: {
42 guild: invite.guild.id
pineafane625d782022-05-09 18:04:32 +010043 }
pineafan63fc5e22022-08-04 22:04:10 +010044 };
45 log(data);
pineafane625d782022-05-09 18:04:32 +010046}