blob: fb35b7eaf6e0bf79afeeb7cdd1e374ba9bbd2849 [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");
pineafan0f5cc782022-08-12 21:55:42 +010012 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === invite.inviterId).first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
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: {
24 channel: entry(invite.channel.id, renderChannel(invite.channel)),
25 link: entry(invite.url, invite.url),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
pineafan63fc5e22022-08-04 22:04:10 +010027 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010029 },
30 hidden: {
pineafan0f5cc782022-08-12 21:55:42 +010031 guild: invite.guild!.id
pineafane625d782022-05-09 18:04:32 +010032 }
pineafan63fc5e22022-08-04 22:04:10 +010033 };
34 log(data);
pineafane625d782022-05-09 18:04:32 +010035}