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) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger; |
| 6 | const auditLog = await getAuditLog(invite.guild, "INVITE_DELETE"); |
| 7 | const audit = auditLog.entries.filter(entry => entry.target.id === invite.id).first(); |
| 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), |
| 21 | expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"), |
| 22 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 23 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) |
| 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 | } |