blob: 735ec218b69b6b5e855e71bddbee29fce3a3b19d [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";
pineafan0f5cc782022-08-12 21:55:42 +01004// @ts-expect-error
5import type { HaikuClient } from "jshaiku";
6
pineafan63fc5e22022-08-04 22:04:10 +01007export const event = "inviteCreate";
pineafane625d782022-05-09 18:04:32 +01008
pineafan0f5cc782022-08-12 21:55:42 +01009export async function callback(client: HaikuClient, invite: Invite) {
10 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
Skyler Greyf21323a2022-08-13 23:58:22 +010012 const audit = auditLog.entries
13 .filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId)
14 .first();
pineafan63fc5e22022-08-04 22:04:10 +010015 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 Grey11236ba2022-08-08 21:13:33 +010028 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
pineafan63fc5e22022-08-04 22:04:10 +010029 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010030 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010031 },
32 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010033 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010034 }
pineafan63fc5e22022-08-04 22:04:10 +010035 };
36 log(data);
pineafane625d782022-05-09 18:04:32 +010037}