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 | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 5 | const { |
| 6 | getAuditLog, |
| 7 | log, |
| 8 | NucleusColors, |
| 9 | entry, |
| 10 | renderUser, |
| 11 | renderDelta, |
| 12 | renderChannel |
| 13 | } = invite.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | const audit = auditLog.entries |
| 16 | .filter((entry) => entry.target.id === invite.id) |
| 17 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | if (audit.executor.id === client.user.id) return; |
| 19 | const data = { |
| 20 | meta: { |
| 21 | type: "inviteDelete", |
| 22 | displayName: "Invite Deleted", |
| 23 | calculateType: "guildUpdate", |
| 24 | color: NucleusColors.red, |
| 25 | emoji: "INVITE.DELETE", |
| 26 | timestamp: new Date().getTime() |
| 27 | }, |
| 28 | list: { |
| 29 | channel: entry(invite.channel.id, renderChannel(invite.channel)), |
| 30 | link: entry(invite.url, invite.url), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 31 | expires: entry( |
| 32 | invite.maxAge, |
| 33 | invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never" |
| 34 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 36 | deleted: entry( |
| 37 | new Date().getTime(), |
| 38 | renderDelta(new Date().getTime()) |
| 39 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 40 | }, |
| 41 | hidden: { |
| 42 | guild: invite.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 43 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | }; |
| 45 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 46 | } |