blob: dec234fdf988fca4f600e6e3c4af72bb44efe804 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
2export const event = 'inviteDelete'
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_DELETE');
8 let audit = auditLog.entries.filter(entry => entry.target.id == invite.id).first();
9 if (audit.executor.id == client.user.id) return;
10 let data = {
11 meta: {
12 type: 'inviteDelete',
13 displayName: 'Invite Deleted',
14 calculateType: 'guildUpdate',
15 color: NucleusColors.red,
16 emoji: "INVITE.DELETE",
17 timestamp: new Date().getTime()
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 deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
24 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
25 },
26 hidden: {
27 guild: invite.guild.id
28 }
29 }
30 log(data, invite.client);
31 } catch {}
32}