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