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 = "inviteDelete"; |
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 |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame^] | 10 | const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
| 11 | if (!await isLogging(invite.guild.id, "guildUpdate")) return; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 12 | const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteDelete)) |
| 13 | .filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!; |
| 14 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | const data = { |
| 16 | meta: { |
| 17 | type: "inviteDelete", |
| 18 | displayName: "Invite Deleted", |
| 19 | calculateType: "guildUpdate", |
| 20 | color: NucleusColors.red, |
| 21 | emoji: "INVITE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame^] | 22 | timestamp: Date.now() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 23 | }, |
| 24 | list: { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 25 | channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | link: entry(invite.url, invite.url), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 27 | expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"), |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 28 | deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame^] | 29 | deleted: entry(Date.now(), renderDelta(Date.now())) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | }, |
| 31 | hidden: { |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 32 | guild: invite.guild!.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 33 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | }; |
| 35 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 36 | } |