blob: 76dfc1e6d2bf157187dbb90ac8d06716300b9669 [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001import type { GuildAuditLogsEntry, Invite } from "discord.js";
2// @ts-expect-error
pineafan63fc5e22022-08-04 22:04:10 +01003import humanizeDuration from "humanize-duration";
PineaFan64486c42022-12-28 09:21:04 +00004import type { HaikuClient } from "../utils/haiku/index.js";
pineafan0f5cc782022-08-12 21:55:42 +01005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "inviteCreate";
pineafane625d782022-05-09 18:04:32 +01007
pineafan0f5cc782022-08-12 21:55:42 +01008export async function callback(client: HaikuClient, invite: Invite) {
9 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
Skyler Greyf21323a2022-08-13 23:58:22 +010011 const audit = auditLog.entries
12 .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
13 .first();
pineafan63fc5e22022-08-04 22:04:10 +010014 if (audit.executor.id === client.user.id) return;
15 const data = {
16 meta: {
17 type: "inviteCreate",
18 displayName: "Invite Created",
19 calculateType: "guildUpdate",
20 color: NucleusColors.green,
21 emoji: "INVITE.CREATE",
22 timestamp: invite.createdTimestamp
23 },
24 list: {
25 channel: entry(invite.channel.id, renderChannel(invite.channel)),
26 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
pineafan63fc5e22022-08-04 22:04:10 +010028 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010029 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010030 },
31 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010032 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010033 }
pineafan63fc5e22022-08-04 22:04:10 +010034 };
35 log(data);
pineafane625d782022-05-09 18:04:32 +010036}