blob: 1cbed02065ea3c0c7ce334764975fd6c8f3cbb52 [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) {
pineafan63fc5e22022-08-04 22:04:10 +01005 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger;
6 const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
7 const audit = auditLog.entries.filter(entry => entry.target.id === invite.id).first();
8 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),
21 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
22 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
23 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
24 },
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}