fix: guild helpers

This commit is contained in:
Skillz4Killz
2021-12-05 18:42:07 +00:00
committed by GitHub
parent 9e193cae41
commit 072d54b892
5 changed files with 45 additions and 5 deletions

View File

@@ -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<GuildPreview>(bot.rest, "get", bot.constants.endpoints.GUILD_PREVIEW(guildId));
const result = await bot.rest.runMethod<GuildPreview>(
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,
};
}

View File

@@ -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<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
| {

View File

@@ -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<WelcomeScreen>(
const result = await bot.rest.runMethod<WelcomeScreen>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId)
);
return bot.transformers.welcomeScreen(bot, result);
}

View File

@@ -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<GuildWidgetDetails>(
const result = await bot.rest.runMethod<GuildWidgetDetails>(
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,
};
}

View File

@@ -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<GuildWidget>(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId));
const result = await bot.rest.runMethod<GuildWidget>(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId));
return bot.transformers.widget(bot, result);
}