blob: 5d47bf8e9d16503290328cb87a8621cdc251b7e5 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
2export const event = 'inviteCreate'
3
4export async function callback(client, invite) {
5 try {
6 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger
7 let auditLog = await getAuditLog(invite.guild, 'INVITE_CREATE');
pineafane23c4ec2022-07-27 21:56:27 +01008 let audit = auditLog.entries.filter(entry => entry.target.id === invite.id).first();
9 if (audit.executor.id === client.user.id) return;
pineafane625d782022-05-09 18:04:32 +010010 let data = {
11 meta: {
12 type: 'inviteCreate',
13 displayName: 'Invite Created',
14 calculateType: 'guildUpdate',
15 color: NucleusColors.green,
16 emoji: "INVITE.CREATE",
17 timestamp: invite.createdTimestamp
18 },
19 list: {
20 channel: entry(invite.channel.id, renderChannel(invite.channel)),
21 link: entry(invite.url, invite.url),
22 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : 'Never'),
23 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
24 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
25 },
26 hidden: {
27 guild: invite.guild.id
28 }
29 }
pineafan4edb7762022-06-26 19:21:04 +010030 log(data);
pineafane625d782022-05-09 18:04:32 +010031 } catch {}
32}