From 97c344783bc8ae48853d0388ff7c2f81fcfc4880 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 25 Aug 2022 15:21:07 +0000 Subject: [PATCH] fix: get invite helper. Closes #2389 --- helpers/invites/getInvites.ts | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/helpers/invites/getInvites.ts b/helpers/invites/getInvites.ts index d7509a7a5..93ef62344 100644 --- a/helpers/invites/getInvites.ts +++ b/helpers/invites/getInvites.ts @@ -1,6 +1,6 @@ -import { Collection } from "../../util/collection.ts"; import type { Bot } from "../../bot.ts"; import { DiscordInviteMetadata } from "../../types/discord.ts"; +import { Collection } from "../../util/collection.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ export async function getInvites(bot: Bot, guildId: bigint) { @@ -14,6 +14,57 @@ export async function getInvites(bot: Bot, guildId: bigint) { result.map((invite) => [ invite.code, { + code: invite.code, + type: invite.target_type, + expiresAt: invite.expires_at ? Date.parse(invite.expires_at) : undefined, + guild: invite.guild + ? { + id: bot.transformers.snowflake(invite.guild.id!), + name: invite.guild.name, + splash: invite.guild.splash ? bot.utils.iconHashToBigInt(invite.guild.splash) : undefined, + banner: invite.guild.banner ? bot.utils.iconHashToBigInt(invite.guild.banner) : undefined, + icon: invite.guild.icon ? bot.utils.iconHashToBigInt(invite.guild.icon) : undefined, + description: invite.guild.description, + features: invite.guild.features, + verificationLevel: invite.guild.verification_level, + vanityUrlCode: invite.guild.vanity_url_code, + premiumSubscriptionCount: invite.guild.premium_subscription_count, + nsfw_level: invite.guild.nsfw_level, + welcomeScreen: invite.guild.welcome_screen + ? { + description: invite.guild.welcome_screen.description, + channels: invite.guild.welcome_screen.welcome_channels.map((channel) => ({ + id: bot.transformers.snowflake(channel.channel_id), + description: channel.description, + emoji: { + id: channel.emoji_id ? bot.transformers.snowflake(channel.emoji_id) : undefined, + name: channel.emoji_name, + }, + })), + } + : undefined, + } + : undefined, + channel: invite.channel + ? { + id: bot.transformers.snowflake(invite.channel.id!), + name: invite.channel.name, + type: invite.channel.type, + } + : undefined, + inviter: invite.inviter + ? { + id: bot.transformers.snowflake(invite.inviter.id), + username: invite.inviter.username, + avatar: invite.inviter.avatar ? bot.utils.iconHashToBigInt(invite.inviter.avatar) : undefined, + // avatarDecoration: invite.inviter.avatar_decoration + // ? bot.utils.iconHashToBigInt(invite.inviter.avatar_decoration) + // : undefined, + discriminator: invite.inviter.discriminator, + publicFlags: invite.inviter.public_flags, + } + : undefined, + // Metadata structure uses: invite.uses, maxUses: invite.max_uses, maxAge: invite.max_age,