diff --git a/src/helpers/channels/getStageInstance.ts b/src/helpers/channels/getStageInstance.ts index 6cded1faa..4f9d41c92 100644 --- a/src/helpers/channels/getStageInstance.ts +++ b/src/helpers/channels/getStageInstance.ts @@ -3,5 +3,16 @@ import type { Bot } from "../../bot.ts"; /** Gets the stage instance associated with the Stage channel, if it exists. */ export async function getStageInstance(bot: Bot, channelId: bigint) { - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.STAGE_INSTANCE(channelId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.STAGE_INSTANCE(channelId) + ); + + return { + id: bot.transformers.snowflake(result.id), + guildId: bot.transformers.snowflake(result.guild_id), + channelId: bot.transformers.snowflake(result.channel_id), + topic: result.topic, + }; } diff --git a/src/helpers/channels/threads/startThreadWithoutMessage.ts b/src/helpers/channels/threads/startThreadWithoutMessage.ts index 8498239a0..94584f5ae 100644 --- a/src/helpers/channels/threads/startThreadWithoutMessage.ts +++ b/src/helpers/channels/threads/startThreadWithoutMessage.ts @@ -4,8 +4,18 @@ import type { Bot } from "../../../bot.ts"; /** Creates a new private thread. Returns a thread channel. */ export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, options: StartThreadWithoutMessage) { - return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), { - name: options.name, - auto_archive_duration: options.autoArchiveDuration, + const result = await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.THREAD_START_PRIVATE(channelId), + { + name: options.name, + auto_archive_duration: options.autoArchiveDuration, + } + ); + + return bot.transformers.channel(bot, { + channel: result, + guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined, }); } diff --git a/src/helpers/channels/updateVoiceState.ts b/src/helpers/channels/updateVoiceState.ts index 0884111ec..55fb15f3b 100644 --- a/src/helpers/channels/updateVoiceState.ts +++ b/src/helpers/channels/updateVoiceState.ts @@ -13,7 +13,7 @@ import type { Bot } from "../../bot.ts"; * - When suppressed, the user will have their `request_to_speak_timestamp` removed. */ export async function updateBotVoiceState(bot: Bot, guildId: bigint, options: UpdateSelfVoiceState) { - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId), { + await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId), { channel_id: options.channelId, suppress: options.suppress, request_to_speak_timestamp: options.requestToSpeakTimestamp @@ -34,7 +34,7 @@ export async function updateBotVoiceState(bot: Bot, guildId: bigint, options: Up * - When suppressed, the user will have their `request_to_speak_timestamp` removed. */ export async function updateUserVoiceState(bot: Bot, guildId: bigint, options: UpdateOthersVoiceState) { - return await bot.rest.runMethod( + await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId, options.userId), diff --git a/src/helpers/discovery/addDiscoverySubcategory.ts b/src/helpers/discovery/addDiscoverySubcategory.ts index 226bb6b57..0107c863b 100644 --- a/src/helpers/discovery/addDiscoverySubcategory.ts +++ b/src/helpers/discovery/addDiscoverySubcategory.ts @@ -3,7 +3,7 @@ import type { Bot } from "../../bot.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { - return await bot.rest.runMethod( + await bot.rest.runMethod( bot.rest, "post", bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId) diff --git a/src/helpers/discovery/editDiscovery.ts b/src/helpers/discovery/editDiscovery.ts index 1480f29d6..f00027f24 100644 --- a/src/helpers/discovery/editDiscovery.ts +++ b/src/helpers/discovery/editDiscovery.ts @@ -4,7 +4,7 @@ import type { Bot } from "../../bot.ts"; /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.DISCOVERY_METADATA(guildId), @@ -14,4 +14,18 @@ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuild emoji_discoverability_enabled: data.emojiDiscoverabilityEnabled, } ); + + return { + guildId, + primaryCategoryId: result.primary_category_id, + keywords: result.keywords ?? undefined, + emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled, + partnerActionedTimestamp: result.partner_actioned_timestamp + ? Date.parse(result.partner_actioned_timestamp) + : undefined, + partnerApplicationTimestamp: result.partner_application_timestamp + ? Date.parse(result.partner_application_timestamp) + : undefined, + categoryIds: result.category_ids, + }; } diff --git a/src/helpers/discovery/getDiscovery.ts b/src/helpers/discovery/getDiscovery.ts index 224837df3..3bcce91db 100644 --- a/src/helpers/discovery/getDiscovery.ts +++ b/src/helpers/discovery/getDiscovery.ts @@ -3,9 +3,23 @@ import type { Bot } from "../../bot.ts"; /** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */ export async function getDiscovery(bot: Bot, guildId: bigint) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "get", bot.constants.endpoints.DISCOVERY_METADATA(guildId) ); + + return { + guildId, + primaryCategoryId: result.primary_category_id, + keywords: result.keywords ?? undefined, + emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled, + partnerActionedTimestamp: result.partner_actioned_timestamp + ? Date.parse(result.partner_actioned_timestamp) + : undefined, + partnerApplicationTimestamp: result.partner_application_timestamp + ? Date.parse(result.partner_application_timestamp) + : undefined, + categoryIds: result.category_ids, + }; } diff --git a/src/helpers/emojis/editEmoji.ts b/src/helpers/emojis/editEmoji.ts index b08ecf300..c371ba16d 100644 --- a/src/helpers/emojis/editEmoji.ts +++ b/src/helpers/emojis/editEmoji.ts @@ -4,5 +4,12 @@ import type { Bot } from "../../bot.ts"; /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) { - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), options); + const result = await bot.rest.runMethod( + bot.rest, + "patch", + bot.constants.endpoints.GUILD_EMOJI(guildId, id), + options + ); + + return bot.transformers.emoji(bot, result); } diff --git a/src/helpers/emojis/getEmoji.ts b/src/helpers/emojis/getEmoji.ts index 84a897f40..17287b174 100644 --- a/src/helpers/emojis/getEmoji.ts +++ b/src/helpers/emojis/getEmoji.ts @@ -6,5 +6,11 @@ import type { Bot } from "../../bot.ts"; * Returns an emoji for the given guild and emoji Id. */ export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint) { - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId) + ); + + return bot.transformers.emoji(bot, result); } diff --git a/src/helpers/guilds/getVanityUrl.ts b/src/helpers/guilds/getVanityUrl.ts index 643fe3bdd..1ee1e0b86 100644 --- a/src/helpers/guilds/getVanityUrl.ts +++ b/src/helpers/guilds/getVanityUrl.ts @@ -3,10 +3,14 @@ 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) { - return await bot.rest.runMethod< - | (Partial & Pick) - | { - code: null; - } - >(bot.rest, "get", bot.constants.endpoints.GUILD_VANITY_URL(guildId)); + const result = await bot.rest.runMethod>( + bot.rest, + "get", + bot.constants.endpoints.GUILD_VANITY_URL(guildId) + ); + + return { + uses: result.uses, + code: result.code, + }; } diff --git a/src/helpers/guilds/getVoiceRegions.ts b/src/helpers/guilds/getVoiceRegions.ts index 53b090266..36f016665 100644 --- a/src/helpers/guilds/getVoiceRegions.ts +++ b/src/helpers/guilds/getVoiceRegions.ts @@ -10,5 +10,10 @@ export async function getVoiceRegions(bot: Bot, guildId: bigint) { bot.constants.endpoints.GUILD_REGIONS(guildId) ); - return new Collection(result.map((region) => [region.id, region])); + return new Collection( + result.map((reg) => { + const region = bot.transformers.voiceRegion(bot, reg); + return [region.id, region]; + }) + ); } diff --git a/src/helpers/misc/editBotProfile.ts b/src/helpers/misc/editBotProfile.ts index 8e26d42a7..eb55b1a2e 100644 --- a/src/helpers/misc/editBotProfile.ts +++ b/src/helpers/misc/editBotProfile.ts @@ -26,8 +26,10 @@ export async function editBotProfile(bot: Bot, options: { username?: string; bot const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL; - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { + const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { username: options.username?.trim(), avatar, }); + + return bot.transformers.user(bot, result); } diff --git a/src/helpers/misc/getUser.ts b/src/helpers/misc/getUser.ts index 8b6a170c6..c56638fc0 100644 --- a/src/helpers/misc/getUser.ts +++ b/src/helpers/misc/getUser.ts @@ -4,5 +4,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ export async function getUser(bot: Bot, userId: bigint) { - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.USER(userId)); + const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.USER(userId)); + + return bot.transformers.user(bot, result); } diff --git a/src/helpers/templates/deleteGuildTemplate.ts b/src/helpers/templates/deleteGuildTemplate.ts index 720b34c27..ac297ecee 100644 --- a/src/helpers/templates/deleteGuildTemplate.ts +++ b/src/helpers/templates/deleteGuildTemplate.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; * Requires the `MANAGE_GUILD` permission. */ export async function deleteGuildTemplate(bot: Bot, guildId: bigint, templateCode: string) { - return await bot.rest.runMethod