pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import humanizeDuration from "humanize-duration"; |
| 2 | export const event = "inviteDelete"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 3 | |
| 4 | export async function callback(client, invite) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 7 | const audit = auditLog.entries.filter((entry) => entry.target.id === invite.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | if (audit.executor.id === client.user.id) return; |
| 9 | const data = { |
| 10 | meta: { |
| 11 | type: "inviteDelete", |
| 12 | displayName: "Invite Deleted", |
| 13 | calculateType: "guildUpdate", |
| 14 | color: NucleusColors.red, |
| 15 | emoji: "INVITE.DELETE", |
| 16 | timestamp: new Date().getTime() |
| 17 | }, |
| 18 | list: { |
| 19 | channel: entry(invite.channel.id, renderChannel(invite.channel)), |
| 20 | link: entry(invite.url, invite.url), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 21 | expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 23 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 24 | }, |
| 25 | hidden: { |
| 26 | guild: invite.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 27 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | }; |
| 29 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 30 | } |