blob: acfc9dd406eb113a229af40589106a570126768e [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');
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: '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 }
pineafan4edb7762022-06-26 19:21:04 +010030 log(data);
pineafane625d782022-05-09 18:04:32 +010031 } catch {}
32}