TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 1 | import { AuditLogEvent, Guild, GuildAuditLogsEntry, GuildChannel, Invite } from "discord.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 2 | // @ts-expect-error |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import humanizeDuration from "humanize-duration"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 4 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 5 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | export const event = "inviteCreate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 8 | export async function callback(client: NucleusClient, invite: Invite) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 9 | if (!invite.guild) return; // This is a DM invite (not a guild invite |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 10 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 11 | if (!(await isLogging(invite.guild.id, "guildUpdate"))) return; |
| 12 | const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteCreate)).filter( |
| 13 | (entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code |
| 14 | )[0]!; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 15 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | const data = { |
| 17 | meta: { |
| 18 | type: "inviteCreate", |
| 19 | displayName: "Invite Created", |
| 20 | calculateType: "guildUpdate", |
| 21 | color: NucleusColors.green, |
| 22 | emoji: "INVITE.CREATE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 23 | timestamp: invite.createdTimestamp ?? Date.now() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 24 | }, |
| 25 | list: { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 26 | channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 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"), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 29 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 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 | } |