From 072d54b8923636f14a1e33ca17c166f80f0a04cf Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 5 Dec 2021 18:42:07 +0000 Subject: [PATCH] fix: guild helpers --- src/helpers/guilds/getGuildPreview.ts | 19 ++++++++++++++++++- src/helpers/guilds/getVanityUrl.ts | 2 +- src/helpers/guilds/getWelcomeScreen.ts | 4 +++- src/helpers/guilds/getWidget.ts | 21 ++++++++++++++++++++- src/helpers/guilds/getWidgetSettings.ts | 4 +++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/helpers/guilds/getGuildPreview.ts b/src/helpers/guilds/getGuildPreview.ts index d552d6720..90905f8b8 100644 --- a/src/helpers/guilds/getGuildPreview.ts +++ b/src/helpers/guilds/getGuildPreview.ts @@ -3,5 +3,22 @@ import type { Bot } from "../../bot.ts"; /** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ export async function getGuildPreview(bot: Bot, guildId: bigint) { - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_PREVIEW(guildId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_PREVIEW(guildId) + ); + + return { + id: bot.transformers.snowflake(result.id), + name: result.name, + icon: result.icon ?? undefined, + splash: result.splash ?? undefined, + discoverySplash: result.discovery_splash ?? undefined, + emojis: result.emojis.map((emoji) => bot.transformers.emoji(bot, emoji)), + features: result.features, + approximateMemberCount: result.approximate_member_count, + approximatePresenceCount: result.approximate_presence_count, + description: result.description ?? undefined, + }; } diff --git a/src/helpers/guilds/getVanityUrl.ts b/src/helpers/guilds/getVanityUrl.ts index 3edba9272..643fe3bdd 100644 --- a/src/helpers/guilds/getVanityUrl.ts +++ b/src/helpers/guilds/getVanityUrl.ts @@ -2,7 +2,7 @@ import type { InviteMetadata } from "../../types/invites/inviteMetadata.ts"; import type { Bot } from "../../bot.ts"; /** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */ -export async function getVanityURL(bot: Bot, guildId: bigint) { +export async function getVanityUrl(bot: Bot, guildId: bigint) { return await bot.rest.runMethod< | (Partial & Pick) | { diff --git a/src/helpers/guilds/getWelcomeScreen.ts b/src/helpers/guilds/getWelcomeScreen.ts index d40145d1b..06e6e0fdc 100644 --- a/src/helpers/guilds/getWelcomeScreen.ts +++ b/src/helpers/guilds/getWelcomeScreen.ts @@ -2,9 +2,11 @@ import type { WelcomeScreen } from "../../types/guilds/welcomeScreen.ts"; import type { Bot } from "../../bot.ts"; export async function getWelcomeScreen(bot: Bot, guildId: bigint) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId) ); + + return bot.transformers.welcomeScreen(bot, result); } diff --git a/src/helpers/guilds/getWidget.ts b/src/helpers/guilds/getWidget.ts index deb1b1e34..c51cc0a58 100644 --- a/src/helpers/guilds/getWidget.ts +++ b/src/helpers/guilds/getWidget.ts @@ -3,9 +3,28 @@ import type { Bot } from "../../bot.ts"; /** Returns the widget for the guild. */ export async function getWidget(bot: Bot, guildId: bigint) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json` ); + + return { + id: bot.transformers.snowflake(result.id), + name: result.name, + instantInvite: result.instant_invite, + channels: result.channels.map((channel) => ({ + id: bot.transformers.snowflake(channel.id), + name: channel.name, + position: channel.position, + })), + members: result.members.map((member) => ({ + id: bot.transformers.snowflake(member.id), + username: member.username, + discriminator: Number(member.discriminator), + avatar: member.avatar ? bot.utils.iconHashToBigInt(member.avatar) : undefined, + status: member.status, + })), + presenceCount: result.presence_count, + }; } diff --git a/src/helpers/guilds/getWidgetSettings.ts b/src/helpers/guilds/getWidgetSettings.ts index 4131916b1..5d6c49bf5 100644 --- a/src/helpers/guilds/getWidgetSettings.ts +++ b/src/helpers/guilds/getWidgetSettings.ts @@ -3,5 +3,7 @@ import type { Bot } from "../../bot.ts"; /** Returns the guild widget object. Requires the MANAGE_GUILD permission. */ export async function getWidgetSettings(bot: Bot, guildId: bigint) { - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId)); + + return bot.transformers.widget(bot, result); }