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 = "inviteCreate"; |
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_CREATE"); |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 12 | const audit = auditLog.entries |
| 13 | .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId) |
| 14 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | if (audit.executor.id === client.user.id) return; |
| 16 | const data = { |
| 17 | meta: { |
| 18 | type: "inviteCreate", |
| 19 | displayName: "Invite Created", |
| 20 | calculateType: "guildUpdate", |
| 21 | color: NucleusColors.green, |
| 22 | emoji: "INVITE.CREATE", |
| 23 | timestamp: invite.createdTimestamp |
| 24 | }, |
| 25 | list: { |
| 26 | channel: entry(invite.channel.id, renderChannel(invite.channel)), |
| 27 | link: entry(invite.url, invite.url), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 28 | expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 30 | created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | }, |
| 32 | hidden: { |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 33 | guild: invite.guild!.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 34 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | }; |
| 36 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } |