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) { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame^] | 9 | if(!invite.guild) return; // This is a DM invite (not a guild invite |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 10 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame^] | 11 | const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteCreate)) |
| 12 | .filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!; |
| 13 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const data = { |
| 15 | meta: { |
| 16 | type: "inviteCreate", |
| 17 | displayName: "Invite Created", |
| 18 | calculateType: "guildUpdate", |
| 19 | color: NucleusColors.green, |
| 20 | emoji: "INVITE.CREATE", |
| 21 | timestamp: invite.createdTimestamp |
| 22 | }, |
| 23 | list: { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame^] | 24 | channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 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"), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame^] | 27 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 28 | created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp!)) |
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 | } |