From 5f1b82a4e8e349c7d30ab91f2b3355899c04cdde Mon Sep 17 00:00:00 2001 From: ayntee Date: Fri, 2 Apr 2021 23:18:51 +0400 Subject: [PATCH] refactor: remove RequestManager and use runMethod() (#732) * fix(rest/process_request): use DiscordHTTPResponseCodes * refactor: remove RequestManager * refactor: remove RequestManager and use runMethod() --- src/helpers/channels/create_channel.ts | 10 ++++---- src/helpers/channels/delete_channel.ts | 5 ++-- .../channels/delete_channel_overwrite.ts | 5 ++-- src/helpers/channels/edit_channel.ts | 14 +++++++---- .../channels/edit_channel_overwrite.ts | 5 ++-- src/helpers/channels/follow_channel.ts | 10 ++++---- src/helpers/channels/get_channel.ts | 10 ++++---- src/helpers/channels/get_channel_webhooks.ts | 5 ++-- src/helpers/channels/get_channels.ts | 10 ++++---- src/helpers/channels/get_pins.ts | 10 ++++---- src/helpers/channels/start_typing.ts | 7 ++++-- src/helpers/channels/swap_channels.ts | 5 ++-- src/helpers/commands/create_slash_command.ts | 5 ++-- src/helpers/commands/delete_slash_command.ts | 7 +++--- src/helpers/commands/delete_slash_response.ts | 5 ++-- src/helpers/commands/edit_slash_response.ts | 5 ++-- src/helpers/commands/get_slash_command.ts | 5 ++-- src/helpers/commands/get_slash_commands.ts | 14 ++++++----- .../commands/send_interaction_response.ts | 7 +++--- src/helpers/commands/upsert_slash_command.ts | 5 ++-- src/helpers/commands/upsert_slash_commands.ts | 5 ++-- src/helpers/emojis/create_emoji.ts | 4 ++-- src/helpers/emojis/delete_emoji.ts | 5 ++-- src/helpers/emojis/edit_emoji.ts | 5 ++-- src/helpers/emojis/get_emoji.ts | 6 +++-- src/helpers/emojis/get_emojis.ts | 8 +++---- src/helpers/guilds/create_guild.ts | 12 ++++++---- src/helpers/guilds/delete_server.ts | 4 ++-- src/helpers/guilds/edit_guild.ts | 5 ++-- src/helpers/guilds/edit_widget.ts | 14 +++++++---- src/helpers/guilds/get_audit_logs.ts | 23 +++++++++++-------- .../guilds/get_available_voice_regions.ts | 4 ++-- src/helpers/guilds/get_ban.ts | 5 ++-- src/helpers/guilds/get_bans.ts | 10 ++++---- src/helpers/guilds/get_guild.ts | 4 ++-- src/helpers/guilds/get_guild_preview.ts | 4 ++-- src/helpers/guilds/get_prune_count.ts | 5 ++-- src/helpers/guilds/get_vainty_url.ts | 7 ++++-- src/helpers/guilds/get_voice_regions.ts | 4 ++-- src/helpers/guilds/get_widget.ts | 4 ++-- src/helpers/guilds/get_widget_settings.ts | 4 ++-- src/helpers/guilds/leave_guild.ts | 4 ++-- .../integrations/delete_integration.ts | 5 ++-- src/helpers/integrations/edit_integration.ts | 5 ++-- src/helpers/integrations/get_integrations.ts | 5 ++-- src/helpers/integrations/sync_integration.ts | 5 ++-- src/helpers/invites/create_invite.ts | 5 ++-- src/helpers/invites/delete_invite.ts | 4 ++-- src/helpers/invites/get_channel_invites.ts | 7 ++++-- src/helpers/invites/get_invite.ts | 4 ++-- src/helpers/invites/get_invites.ts | 4 ++-- src/helpers/members/ban_member.ts | 4 ++-- src/helpers/members/edit_bot_nickname.ts | 9 ++++---- src/helpers/members/edit_bot_profile.ts | 13 ++++------- src/helpers/members/edit_member.ts | 5 ++-- src/helpers/members/get_member.ts | 3 ++- src/helpers/members/get_members.ts | 20 +++++++++++----- src/helpers/members/kick_member.ts | 5 ++-- src/helpers/members/prune_members.ts | 5 ++-- src/helpers/members/send_direct_message.ts | 9 ++++---- src/helpers/members/unban_member.ts | 7 ++++-- src/helpers/messages/add_reaction.ts | 5 ++-- src/helpers/messages/delete_message.ts | 5 ++-- src/helpers/messages/delete_messages.ts | 5 ++-- src/helpers/messages/edit_message.ts | 5 ++-- src/helpers/messages/get_message.ts | 10 ++++---- src/helpers/messages/get_messages.ts | 12 ++++++---- src/helpers/messages/get_reactions.ts | 12 ++++++---- src/helpers/messages/pin_message.ts | 5 ++-- src/helpers/messages/publish_message.ts | 10 ++++---- src/helpers/messages/remove_all_reactions.ts | 5 ++-- src/helpers/messages/remove_reaction.ts | 5 ++-- src/helpers/messages/remove_reaction_emoji.ts | 5 ++-- src/helpers/messages/remove_user_reaction.ts | 5 ++-- src/helpers/messages/send_message.ts | 10 ++++---- src/helpers/messages/unpin_message.ts | 5 ++-- src/helpers/misc/get_gateway_bot.ts | 6 ++--- src/helpers/misc/get_user.ts | 4 ++-- src/helpers/roles/add_role.ts | 5 ++-- src/helpers/roles/create_role.ts | 4 ++-- src/helpers/roles/delete_role.ts | 7 ++++-- src/helpers/roles/edit_role.ts | 18 +++++++++------ src/helpers/roles/get_roles.ts | 4 ++-- src/helpers/roles/remove_role.ts | 5 ++-- src/helpers/roles/swap_roles.ts | 5 ++-- .../templates/create_guild_from_template.ts | 5 ++-- .../templates/create_guild_template.ts | 12 ++++++---- .../templates/delete_guild_template.ts | 10 ++++---- src/helpers/templates/edit_guild_template.ts | 12 ++++++---- src/helpers/templates/get_guild_templates.ts | 10 ++++---- src/helpers/templates/get_template.ts | 10 ++++---- src/helpers/templates/sync_guild_template.ts | 10 ++++---- src/helpers/webhooks/create_webhook.ts | 5 ++-- src/helpers/webhooks/delete_webhook.ts | 7 ++++-- .../webhooks/delete_webhook_message.ts | 5 ++-- .../webhooks/delete_webhook_with_token.ts | 5 ++-- src/helpers/webhooks/edit_webhook.ts | 14 +++++++---- src/helpers/webhooks/edit_webhook_message.ts | 5 ++-- .../webhooks/edit_webhook_with_token.ts | 5 ++-- src/helpers/webhooks/execute_webhook.ts | 5 ++-- src/helpers/webhooks/get_webhook.ts | 4 ++-- .../webhooks/get_webhook_with_token.ts | 7 ++++-- src/helpers/webhooks/get_webhooks.ts | 4 ++-- src/rest/request_manager.ts | 19 --------------- src/rest/rest.ts | 7 +----- src/util/constants.ts | 2 +- 106 files changed, 418 insertions(+), 326 deletions(-) delete mode 100644 src/rest/request_manager.ts diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 985a848db..daf1b2040 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuildChannel, @@ -28,9 +28,8 @@ export async function createChannel( await requireBotGuildPermissions(guildId, [...requiredPerms]); - const result = (await RequestManager.post( - endpoints.GUILD_CHANNELS(guildId), - { + const result = + (await rest.runMethod("post", endpoints.GUILD_CHANNELS(guildId), { ...options, name, permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ @@ -40,8 +39,7 @@ export async function createChannel( deny: calculateBits(perm.deny), })), type: options?.type || DiscordChannelTypes.GUILD_TEXT, - }, - )) as DiscordChannel; + })) as DiscordChannel; const channelStruct = await structures.createChannelStruct(result); await cacheHandlers.set("channels", channelStruct.id, channelStruct); diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index 934e65331..3a2e92797 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -23,7 +23,8 @@ export async function deleteChannel( throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED); } - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_BASE(channelId), { reason }, ); diff --git a/src/helpers/channels/delete_channel_overwrite.ts b/src/helpers/channels/delete_channel_overwrite.ts index e086cf107..3b39301e7 100644 --- a/src/helpers/channels/delete_channel_overwrite.ts +++ b/src/helpers/channels/delete_channel_overwrite.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,7 +10,8 @@ export async function deleteChannelOverwrite( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), ); diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index e466fcf96..b6a7eb6a6 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -56,10 +56,14 @@ export async function editChannel( }), }; - const result = await RequestManager.patch(endpoints.CHANNEL_BASE(channelId), { - ...payload, - reason, - }); + const result = await rest.runMethod( + "patch", + endpoints.CHANNEL_BASE(channelId), + { + ...payload, + reason, + }, + ); return result; } diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index 3df0ee6b6..e68b357e6 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Overwrite } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { @@ -15,7 +15,8 @@ export async function editChannelOverwrite( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.put( + const result = await rest.runMethod( + "put", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), { allow: calculateBits(options.allow), diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index 03483f9f3..bd44d8bc7 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { DiscordFollowedChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -10,12 +10,10 @@ export async function followChannel( ) { await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]); - const data = (await RequestManager.post( - endpoints.CHANNEL_FOLLOW(sourceChannelId), - { + const data = + (await rest.runMethod("post", endpoints.CHANNEL_FOLLOW(sourceChannelId), { webhook_channel_id: targetChannelId, - }, - )) as DiscordFollowedChannel; + })) as DiscordFollowedChannel; return data.webhook_id; } diff --git a/src/helpers/channels/get_channel.ts b/src/helpers/channels/get_channel.ts index 9b48f0b7f..eb2268252 100644 --- a/src/helpers/channels/get_channel.ts +++ b/src/helpers/channels/get_channel.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -9,9 +9,11 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ export async function getChannel(channelId: string, addToCache = true) { - const result = (await RequestManager.get( - endpoints.CHANNEL_BASE(channelId), - )) as DiscordChannel; + const result = + (await rest.runMethod( + "get", + endpoints.CHANNEL_BASE(channelId), + )) as DiscordChannel; const channelStruct = await structures.createChannelStruct( result, diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index 8767b9468..050c21e01 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { DiscordWebhook } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -7,7 +7,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function getChannelWebhooks(channelId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); - const result = await RequestManager.get( + const result = await rest.runMethod( + "get", endpoints.CHANNEL_WEBHOOKS(channelId), ); diff --git a/src/helpers/channels/get_channels.ts b/src/helpers/channels/get_channels.ts index 8508e0b7a..15e7b9cbb 100644 --- a/src/helpers/channels/get_channels.ts +++ b/src/helpers/channels/get_channels.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -9,9 +9,11 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ export async function getChannels(guildId: string, addToCache = true) { - const result = (await RequestManager.get( - endpoints.GUILD_CHANNELS(guildId), - ) as DiscordChannel[]); + const result = + (await rest.runMethod( + "get", + endpoints.GUILD_CHANNELS(guildId), + ) as DiscordChannel[]); return Promise.all(result.map(async (res) => { const channelStruct = await structures.createChannelStruct(res, guildId); diff --git a/src/helpers/channels/get_pins.ts b/src/helpers/channels/get_pins.ts index 296b12a65..14bddf199 100644 --- a/src/helpers/channels/get_pins.ts +++ b/src/helpers/channels/get_pins.ts @@ -1,13 +1,15 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordMessage } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Get pinned messages in this channel. */ export async function getPins(channelId: string) { - const result = (await RequestManager.get( - endpoints.CHANNEL_PINS(channelId), - )) as DiscordMessage[]; + const result = + (await rest.runMethod( + "get", + endpoints.CHANNEL_PINS(channelId), + )) as DiscordMessage[]; return Promise.all( result.map((res) => structures.createMessageStruct(res)), diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 0463b294b..edcaa82a1 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { DiscordChannelTypes, Errors } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts"; @@ -34,7 +34,10 @@ export async function startTyping(channelId: string) { } } - const result = await RequestManager.post(endpoints.CHANNEL_TYPING(channelId)); + const result = await rest.runMethod( + "post", + endpoints.CHANNEL_TYPING(channelId), + ); return result; } diff --git a/src/helpers/channels/swap_channels.ts b/src/helpers/channels/swap_channels.ts index 1ee9b2340..a85b8ca07 100644 --- a/src/helpers/channels/swap_channels.ts +++ b/src/helpers/channels/swap_channels.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { ModifyGuildChannelPositions } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,7 +11,8 @@ export async function swapChannels( throw "You must provide at least two channels to be swapped."; } - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILD_CHANNELS(guildId), channelPositions, ); diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/commands/create_slash_command.ts index c4c745c85..fafa506fb 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/commands/create_slash_command.ts @@ -1,5 +1,5 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; @@ -17,7 +17,8 @@ import { validateSlashCommands } from "../../util/utils.ts"; export async function createSlashCommand(options: CreateSlashCommandOptions) { validateSlashCommands([options], true); - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", options.guildId ? endpoints.COMMANDS_GUILD(applicationId, options.guildId) : endpoints.COMMANDS(applicationId), diff --git a/src/helpers/commands/delete_slash_command.ts b/src/helpers/commands/delete_slash_command.ts index a07d197b6..1eda08083 100644 --- a/src/helpers/commands/delete_slash_command.ts +++ b/src/helpers/commands/delete_slash_command.ts @@ -1,13 +1,14 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Deletes a slash command. */ export function deleteSlashCommand(id: string, guildId?: string) { if (!guildId) { - return RequestManager.delete(endpoints.COMMANDS_ID(applicationId, id)); + return rest.runMethod("delete", endpoints.COMMANDS_ID(applicationId, id)); } - return RequestManager.delete( + return rest.runMethod( + "delete", endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id), ); } diff --git a/src/helpers/commands/delete_slash_response.ts b/src/helpers/commands/delete_slash_response.ts index d18e48bc5..1a9d480e0 100644 --- a/src/helpers/commands/delete_slash_response.ts +++ b/src/helpers/commands/delete_slash_response.ts @@ -1,10 +1,11 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */ export async function deleteSlashResponse(token: string, messageId?: string) { - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", messageId ? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID( applicationId, diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/commands/edit_slash_response.ts index a0e0761e7..94f82a003 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/commands/edit_slash_response.ts @@ -1,5 +1,5 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -48,7 +48,8 @@ export async function editSlashResponse( } } - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", options.messageId ? endpoints.WEBHOOK_MESSAGE(applicationId, token, options.messageId) : endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token), diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/commands/get_slash_command.ts index 49857884e..3cc50bc28 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/commands/get_slash_command.ts @@ -1,10 +1,11 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ export async function getSlashCommand(commandId: string, guildId?: string) { - const result = await RequestManager.get( + const result = await rest.runMethod( + "get", guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId) : endpoints.COMMANDS_ID(applicationId, commandId), diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/commands/get_slash_commands.ts index e7ea2de93..8e86a24bf 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/commands/get_slash_commands.ts @@ -1,15 +1,17 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetch all of the global commands for your application. */ export async function getSlashCommands(guildId?: string) { - const result = (await RequestManager.get( - guildId - ? endpoints.COMMANDS_GUILD(applicationId, guildId) - : endpoints.COMMANDS(applicationId), - )) as SlashCommand[]; + const result = + (await rest.runMethod( + "get", + guildId + ? endpoints.COMMANDS_GUILD(applicationId, guildId) + : endpoints.COMMANDS(applicationId), + )) as SlashCommand[]; return new Collection(result.map((command) => [command.name, command])); } diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/commands/send_interaction_response.ts index 855310393..c60ea83ef 100644 --- a/src/helpers/commands/send_interaction_response.ts +++ b/src/helpers/commands/send_interaction_response.ts @@ -1,6 +1,6 @@ import { applicationId } from "../../bot.ts"; import { cache } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** @@ -16,7 +16,7 @@ export async function sendInteractionResponse( ) { // If its already been executed, we need to send a followup response if (cache.executedSlashCommands.has(token)) { - return RequestManager.post(endpoints.WEBHOOK(applicationId, token), { + return rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), { ...options, }); } @@ -38,7 +38,8 @@ export async function sendInteractionResponse( options.data.allowed_mentions = { parse: [] }; } - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.INTERACTION_ID_TOKEN(id, token), options, ); diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/commands/upsert_slash_command.ts index 0861a05d7..21091f18e 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/commands/upsert_slash_command.ts @@ -1,5 +1,5 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; @@ -13,7 +13,8 @@ export async function upsertSlashCommand( ) { validateSlashCommands([options]); - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId) : endpoints.COMMANDS_ID(applicationId, commandId), diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/commands/upsert_slash_commands.ts index cb0239bc4..a5befc957 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/commands/upsert_slash_commands.ts @@ -1,5 +1,5 @@ import { applicationId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; @@ -14,7 +14,8 @@ export async function upsertSlashCommands( ) { validateSlashCommands(options); - const result = await RequestManager.put( + const result = await rest.runMethod( + "put", guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index d43b83802..1070bf7a9 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -16,7 +16,7 @@ export async function createEmoji( image = await urlToBase64(image); } - const result = await RequestManager.post(endpoints.GUILD_EMOJIS(guildId), { + const result = await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), { ...options, name, image, diff --git a/src/helpers/emojis/delete_emoji.ts b/src/helpers/emojis/delete_emoji.ts index 8beb9648c..64154ccfe 100644 --- a/src/helpers/emojis/delete_emoji.ts +++ b/src/helpers/emojis/delete_emoji.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,7 +10,8 @@ export async function deleteEmoji( ) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.GUILD_EMOJI(guildId, id), { reason }, ); diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index ddff2997b..0c2e125a6 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,7 +10,8 @@ export async function editEmoji( ) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILD_EMOJI(guildId, id), { name: options.name, diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index fc038c59f..edf3f4c25 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; +import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** @@ -12,7 +13,8 @@ export async function getEmoji( emojiId: string, addToCache = true, ) { - const result = (await RequestManager.get( + const result = (await rest.runMethod( + "get", endpoints.GUILD_EMOJI(guildId, emojiId), )) as Emoji; diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index cd9527acc..133723114 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; +import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; /** @@ -8,9 +9,8 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ export async function getEmojis(guildId: string, addToCache = true) { - const result = (await RequestManager.get( - endpoints.GUILD_EMOJIS(guildId), - )) as Emoji[]; + const result = + (await rest.runMethod("get", endpoints.GUILD_EMOJIS(guildId))) as Emoji[]; if (addToCache) { const guild = await cacheHandlers.get("guilds", guildId); diff --git a/src/helpers/guilds/create_guild.ts b/src/helpers/guilds/create_guild.ts index 4be5f47c8..2eb52b212 100644 --- a/src/helpers/guilds/create_guild.ts +++ b/src/helpers/guilds/create_guild.ts @@ -1,13 +1,15 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ export async function createGuild(options: CreateServerOptions) { - const guild = (await RequestManager.post( - endpoints.GUILDS, - options, - )) as CreateGuildPayload; + const guild = + (await rest.runMethod( + "post", + endpoints.GUILDS, + options, + )) as CreateGuildPayload; return structures.createGuildStruct(guild, 0); } diff --git a/src/helpers/guilds/delete_server.ts b/src/helpers/guilds/delete_server.ts index 89696ec54..03da1f717 100644 --- a/src/helpers/guilds/delete_server.ts +++ b/src/helpers/guilds/delete_server.ts @@ -1,10 +1,10 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ export async function deleteServer(guildId: string) { - const result = await RequestManager.delete(endpoints.GUILDS_BASE(guildId)); + const result = await rest.runMethod("delete", endpoints.GUILDS_BASE(guildId)); return result; } diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index 5b76a4558..081b7a64b 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -19,7 +19,8 @@ export async function editGuild(guildId: string, options: GuildEditOptions) { options.splash = await urlToBase64(options.splash); } - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILDS_BASE(guildId), options, ); diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 10cfdb082..f36511cc7 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,10 +10,14 @@ export async function editWidget( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.patch(endpoints.GUILD_WIDGET(guildId), { - enabled, - channel_id: channelId, - }); + const result = await rest.runMethod( + "patch", + endpoints.GUILD_WIDGET(guildId), + { + enabled, + channel_id: channelId, + }, + ); return result; } diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index 1fc86101e..b4563bbe3 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -9,15 +9,18 @@ export async function getAuditLogs( ) { await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]); - const result = await RequestManager.get(endpoints.GUILD_AUDIT_LOGS(guildId), { - ...options, - action_type: options.action_type - ? AuditLogs[options.action_type] - : undefined, - limit: options.limit && options.limit >= 1 && options.limit <= 100 - ? options.limit - : 50, - }); + const result = await rest.runMethod( + "get", + endpoints.GUILD_AUDIT_LOGS(guildId), + { + ...options, + action_type: options.action_type + ? AuditLogs[options.action_type] + : undefined, + limit: options.limit && options.limit >= 1 && options.limit <= 100 + ? options.limit : 50, + }, + ); return result; } diff --git a/src/helpers/guilds/get_available_voice_regions.ts b/src/helpers/guilds/get_available_voice_regions.ts index 42d29c02e..b1f2b0c67 100644 --- a/src/helpers/guilds/get_available_voice_regions.ts +++ b/src/helpers/guilds/get_available_voice_regions.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns an array of voice regions that can be used when creating servers. */ export async function getAvailableVoiceRegions() { - const result = await RequestManager.get(endpoints.VOICE_REGIONS); + const result = await rest.runMethod("get", endpoints.VOICE_REGIONS); return result; } diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index be7fda64e..8d3751965 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getBan(guildId: string, memberId: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await RequestManager.get( + const result = await rest.runMethod( + "get", endpoints.GUILD_BAN(guildId, memberId), ); diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index f7b204421..aabd031c5 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -7,9 +7,11 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getBans(guildId: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const results = (await RequestManager.get( - endpoints.GUILD_BANS(guildId), - )) as BannedUser[]; + const results = + (await rest.runMethod( + "get", + endpoints.GUILD_BANS(guildId), + )) as BannedUser[]; return new Collection( results.map((res) => [res.user.id, res]), diff --git a/src/helpers/guilds/get_guild.ts b/src/helpers/guilds/get_guild.ts index f4482d181..0a46b7d5b 100644 --- a/src/helpers/guilds/get_guild.ts +++ b/src/helpers/guilds/get_guild.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** @@ -9,7 +9,7 @@ import { endpoints } from "../../util/constants.ts"; * So it does not cache the guild, you must do it manually. * */ export async function getGuild(guildId: string, counts = true) { - const result = await RequestManager.get(endpoints.GUILDS_BASE(guildId), { + const result = await rest.runMethod("get", endpoints.GUILDS_BASE(guildId), { with_counts: counts, }); diff --git a/src/helpers/guilds/get_guild_preview.ts b/src/helpers/guilds/get_guild_preview.ts index 5ad6812d7..6d7cc9386 100644 --- a/src/helpers/guilds/get_guild_preview.ts +++ b/src/helpers/guilds/get_guild_preview.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.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(guildId: string) { - const result = await RequestManager.get(endpoints.GUILD_PREVIEW(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId)); return result; } diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index 200ad5d39..3b16b6c9a 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; @@ -12,7 +12,8 @@ export async function getPruneCount(guildId: string, options?: PruneOptions) { await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await RequestManager.get( + const result = await rest.runMethod( + "get", endpoints.GUILD_PRUNE(guildId), camelKeysToSnakeCase(options ?? {}), ) as PrunePayload; diff --git a/src/helpers/guilds/get_vainty_url.ts b/src/helpers/guilds/get_vainty_url.ts index 9c44fb19a..1ccac2a89 100644 --- a/src/helpers/guilds/get_vainty_url.ts +++ b/src/helpers/guilds/get_vainty_url.ts @@ -1,9 +1,12 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */ export async function getVanityURL(guildId: string) { - const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildId)); + const result = await rest.runMethod( + "get", + endpoints.GUILD_VANITY_URL(guildId), + ); return result; } diff --git a/src/helpers/guilds/get_voice_regions.ts b/src/helpers/guilds/get_voice_regions.ts index 828d7af62..8ac73d10a 100644 --- a/src/helpers/guilds/get_voice_regions.ts +++ b/src/helpers/guilds/get_voice_regions.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ export async function getVoiceRegions(guildId: string) { - const result = await RequestManager.get(endpoints.GUILD_REGIONS(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_REGIONS(guildId)); return result; } diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index 52f7adef7..4583dcd98 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the widget for the guild. */ @@ -10,5 +10,5 @@ export async function getWidget(guildId: string, options?: { force: boolean }) { if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); } - return RequestManager.get(`${endpoints.GUILD_WIDGET(guildId)}.json`); + return rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); } diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index dca0b2e7a..3b719e7c6 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getWidgetSettings(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.get(endpoints.GUILD_WIDGET(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_WIDGET(guildId)); return result; } diff --git a/src/helpers/guilds/leave_guild.ts b/src/helpers/guilds/leave_guild.ts index d52bf4eff..d103a0df3 100644 --- a/src/helpers/guilds/leave_guild.ts +++ b/src/helpers/guilds/leave_guild.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Leave a guild */ export async function leaveGuild(guildId: string) { - const result = await RequestManager.delete(endpoints.GUILD_LEAVE(guildId)); + const result = await rest.runMethod("delete", endpoints.GUILD_LEAVE(guildId)); return result; } diff --git a/src/helpers/integrations/delete_integration.ts b/src/helpers/integrations/delete_integration.ts index da0952ce8..375672b9e 100644 --- a/src/helpers/integrations/delete_integration.ts +++ b/src/helpers/integrations/delete_integration.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function deleteIntegration(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.GUILD_INTEGRATION(guildId, id), ); diff --git a/src/helpers/integrations/edit_integration.ts b/src/helpers/integrations/edit_integration.ts index 99b5c7b0c..49e60471c 100644 --- a/src/helpers/integrations/edit_integration.ts +++ b/src/helpers/integrations/edit_integration.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,7 +10,8 @@ export async function editIntegration( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILD_INTEGRATION(guildId, id), options, ); diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 6ecf20487..888dd8f96 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getIntegrations(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.get( + const result = await rest.runMethod( + "get", endpoints.GUILD_INTEGRATIONS(guildId), ); diff --git a/src/helpers/integrations/sync_integration.ts b/src/helpers/integrations/sync_integration.ts index 46c9656f3..643a85c5d 100644 --- a/src/helpers/integrations/sync_integration.ts +++ b/src/helpers/integrations/sync_integration.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function syncIntegration(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.GUILD_INTEGRATION_SYNC(guildId, id), ); diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 4b1c0cdb7..83c9f273a 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -23,7 +23,8 @@ export async function createInvite( options.max_uses = undefined; } - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.CHANNEL_INVITES(channelId), options, ); diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index 25d3650de..de97f59c9 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions, @@ -20,7 +20,7 @@ export async function deleteInvite(channelId: string, inviteCode: string) { await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]); } - const result = await RequestManager.delete(endpoints.INVITE(inviteCode)); + const result = await rest.runMethod("delete", endpoints.INVITE(inviteCode)); return result as InvitePayload; } diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index 893e63613..f5c1fe1b3 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function getChannelInvites(channelId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]); - const result = await RequestManager.get(endpoints.CHANNEL_INVITES(channelId)); + const result = await rest.runMethod( + "get", + endpoints.CHANNEL_INVITES(channelId), + ); return result; } diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 8d0bc8736..a55eaa458 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns an invite for the given code. */ export async function getInvite(inviteCode: string) { - const result = await RequestManager.get(endpoints.INVITE(inviteCode)); + const result = await rest.runMethod("get", endpoints.INVITE(inviteCode)); return result as InvitePayload; } diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index b8a3e80da..c43ff3482 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getInvites(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await RequestManager.get(endpoints.GUILD_INVITES(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_INVITES(guildId)); return result; } diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index cd070399e..7fafc5698 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function ban(guildId: string, id: string, options: BanOptions) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await RequestManager.put(endpoints.GUILD_BAN(guildId, id), { + const result = await rest.runMethod("put", endpoints.GUILD_BAN(guildId, id), { ...options, delete_message_days: options.days, }); diff --git a/src/helpers/members/edit_bot_nickname.ts b/src/helpers/members/edit_bot_nickname.ts index 1f76fbc65..5b182cfcd 100644 --- a/src/helpers/members/edit_bot_nickname.ts +++ b/src/helpers/members/edit_bot_nickname.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -9,10 +9,9 @@ export async function editBotNickname( ) { await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]); - const response = await RequestManager.patch( - endpoints.USER_NICK(guildId), - { nick: nickname }, - ) as { nick: string }; + const response = await rest.runMethod("patch", endpoints.USER_NICK(guildId), { + nick: nickname, + }) as { nick: string }; return response.nick; } diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/members/edit_bot_profile.ts index 447239f5c..c010c9f67 100644 --- a/src/helpers/members/edit_bot_profile.ts +++ b/src/helpers/members/edit_bot_profile.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -25,13 +25,10 @@ export async function editBotProfile(username?: string, botAvatarURL?: string) { } const avatar = botAvatarURL ? await urlToBase64(botAvatarURL) : undefined; - const result = await RequestManager.patch( - endpoints.USER_BOT, - { - username: username?.trim(), - avatar, - }, - ); + const result = await rest.runMethod("patch", endpoints.USER_BOT, { + username: username?.trim(), + avatar, + }); return result; } diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index 4543ac1f2..a7c1a9a9e 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { @@ -64,7 +64,8 @@ export async function editMember( await requireBotGuildPermissions(guildId, [...requiredPerms]); - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILD_MEMBER(guildId, memberId), options, ) as MemberCreatePayload; diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index 4603ee0ca..bc332d57f 100644 --- a/src/helpers/members/get_member.ts +++ b/src/helpers/members/get_member.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -15,7 +16,7 @@ export async function getMember( const guild = await cacheHandlers.get("guilds", guildId); if (!guild && !options?.force) return; - const data = (await RequestManager.get( + const data = (await rest.runMethod("get", endpoints.GUILD_MEMBER(guildId, id), )) as MemberCreatePayload; diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 19ec8f2f3..18126948b 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -1,6 +1,6 @@ import { identifyPayload } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Member, structures } from "../../structures/mod.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; @@ -39,11 +39,19 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) { ); } - const result = (await RequestManager.get( - `${endpoints.GUILD_MEMBERS(guildId)}?limit=${ - membersLeft > 1000 ? 1000 : membersLeft - }${options?.after ? `&after=${options.after}` : ""}`, - )) as MemberCreatePayload[]; + const result = + (await rest.runMethod( + "get", + `${endpoints.GUILD_MEMBERS(guildId)}?limit=${ + membersLeft > 1000 + ? 1000 + : membersLeft + }${ + options?.after + ? `&after=${options.after}` + : "" + }`, + )) as MemberCreatePayload[]; const memberStructures = await Promise.all( result.map(async (member) => { diff --git a/src/helpers/members/kick_member.ts b/src/helpers/members/kick_member.ts index 60b62ba90..fe2fdd2f1 100644 --- a/src/helpers/members/kick_member.ts +++ b/src/helpers/members/kick_member.ts @@ -1,5 +1,5 @@ import { botId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { highestRole, @@ -19,7 +19,8 @@ export async function kick(guildId: string, memberId: string, reason?: string) { await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.GUILD_MEMBER(guildId, memberId), { reason }, ); diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 9529080cd..31e558946 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; @@ -17,7 +17,8 @@ export async function pruneMembers( await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.GUILD_PRUNE(guildId), camelKeysToSnakeCase(options), ); diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index ad501297c..4b7a4b802 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { sendMessage } from "../messages/send_message.ts"; @@ -12,10 +12,9 @@ export async function sendDirectMessage( let dmChannel = await cacheHandlers.get("channels", memberId); if (!dmChannel) { // If not available in cache create a new one. - const dmChannelData = await RequestManager.post( - endpoints.USER_DM, - { recipient_id: memberId }, - ) as DMChannelCreatePayload; + const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, { + recipient_id: memberId, + }) as DMChannelCreatePayload; const channelStruct = await structures.createChannelStruct( dmChannelData as unknown as ChannelCreatePayload, ); diff --git a/src/helpers/members/unban_member.ts b/src/helpers/members/unban_member.ts index 242472bca..db79fe2fd 100644 --- a/src/helpers/members/unban_member.ts +++ b/src/helpers/members/unban_member.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function unban(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await RequestManager.delete(endpoints.GUILD_BAN(guildId, id)); + const result = await rest.runMethod( + "delete", + endpoints.GUILD_BAN(guildId, id), + ); return result; } diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index 06db2b89e..1a5861abb 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -19,7 +19,8 @@ export async function addReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await RequestManager.put( + const result = await rest.runMethod( + "put", endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); diff --git a/src/helpers/messages/delete_message.ts b/src/helpers/messages/delete_message.ts index 806b97302..c053a1787 100644 --- a/src/helpers/messages/delete_message.ts +++ b/src/helpers/messages/delete_message.ts @@ -1,6 +1,6 @@ import { botId } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { delay } from "../../util/utils.ts"; @@ -20,7 +20,8 @@ export async function deleteMessage( if (delayMilliseconds) await delay(delayMilliseconds); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_MESSAGE(channelId, messageId), { reason }, ); diff --git a/src/helpers/messages/delete_messages.ts b/src/helpers/messages/delete_messages.ts index ac11cbea8..5c8cbd34e 100644 --- a/src/helpers/messages/delete_messages.ts +++ b/src/helpers/messages/delete_messages.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -20,7 +20,8 @@ export async function deleteMessages( ); } - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.CHANNEL_BULK_DELETE(channelId), { messages: ids.splice(0, 100), diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index 1a49d0a47..6e74e21c5 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -1,5 +1,5 @@ import { botId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Message, structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -25,7 +25,8 @@ export async function editMessage( throw new Error(Errors.MESSAGE_MAX_LENGTH); } - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.CHANNEL_MESSAGE(message.channelId, message.id), content, ); diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index 3c389b163..55ea57ce9 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -10,9 +10,11 @@ export async function getMessage(channelId: string, id: string) { "READ_MESSAGE_HISTORY", ]); - const result = (await RequestManager.get( - endpoints.CHANNEL_MESSAGE(channelId, id), - )) as MessageCreateOptions; + const result = + (await rest.runMethod( + "get", + endpoints.CHANNEL_MESSAGE(channelId, id), + )) as MessageCreateOptions; return structures.createMessageStruct(result); } diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index c3f0c8639..d70e8ce58 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -19,10 +19,12 @@ export async function getMessages( if (options?.limit && options.limit > 100) return; - const result = (await RequestManager.get( - endpoints.CHANNEL_MESSAGES(channelId), - options, - )) as MessageCreateOptions[]; + const result = + (await rest.runMethod( + "get", + endpoints.CHANNEL_MESSAGES(channelId), + options, + )) as MessageCreateOptions[]; return Promise.all( result.map((res) => structures.createMessageStruct(res)), diff --git a/src/helpers/messages/get_reactions.ts b/src/helpers/messages/get_reactions.ts index 4d6ab8f52..880406b9a 100644 --- a/src/helpers/messages/get_reactions.ts +++ b/src/helpers/messages/get_reactions.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; @@ -9,10 +9,12 @@ export async function getReactions( reaction: string, options?: DiscordGetReactionsParams, ) { - const users = (await RequestManager.get( - endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), - options, - )) as UserPayload[]; + const users = + (await rest.runMethod( + "get", + endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), + options, + )) as UserPayload[]; return new Collection(users.map((user) => [user.id, user])); } diff --git a/src/helpers/messages/pin_message.ts b/src/helpers/messages/pin_message.ts index 8c860fcf8..3e3001142 100644 --- a/src/helpers/messages/pin_message.ts +++ b/src/helpers/messages/pin_message.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function pin(channelId: string, messageId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await RequestManager.put( + const result = await rest.runMethod( + "put", endpoints.CHANNEL_PIN(channelId, messageId), ); diff --git a/src/helpers/messages/publish_message.ts b/src/helpers/messages/publish_message.ts index e3dde4f59..7eb526f58 100644 --- a/src/helpers/messages/publish_message.ts +++ b/src/helpers/messages/publish_message.ts @@ -1,12 +1,14 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Crosspost a message in a News Channel to following channels. */ export async function publishMessage(channelId: string, messageId: string) { - const data = (await RequestManager.post( - endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), - )) as MessageCreateOptions; + const data = + (await rest.runMethod( + "post", + endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), + )) as MessageCreateOptions; return structures.createMessageStruct(data); } diff --git a/src/helpers/messages/remove_all_reactions.ts b/src/helpers/messages/remove_all_reactions.ts index e0bfdefb6..c228ddfde 100644 --- a/src/helpers/messages/remove_all_reactions.ts +++ b/src/helpers/messages/remove_all_reactions.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function removeAllReactions(channelId: string, messageId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId), ); diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index c36ec4136..087cf6659 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Removes a reaction from the bot on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ @@ -13,7 +13,8 @@ export async function removeReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); diff --git a/src/helpers/messages/remove_reaction_emoji.ts b/src/helpers/messages/remove_reaction_emoji.ts index a92bae07d..0ed789a82 100644 --- a/src/helpers/messages/remove_reaction_emoji.ts +++ b/src/helpers/messages/remove_reaction_emoji.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -16,7 +16,8 @@ export async function removeReactionEmoji( reaction = reaction.substring(3, reaction.length - 1); } - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), ); diff --git a/src/helpers/messages/remove_user_reaction.ts b/src/helpers/messages/remove_user_reaction.ts index 1fe4b951b..4ae4ffb2b 100644 --- a/src/helpers/messages/remove_user_reaction.ts +++ b/src/helpers/messages/remove_user_reaction.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -17,7 +17,8 @@ export async function removeUserReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_MESSAGE_REACTION_USER( channelId, messageId, diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index d1844e364..c29b56c03 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { PermissionStrings } from "../../types/mod.ts"; @@ -70,9 +70,8 @@ export async function sendMessage( } } - const result = (await RequestManager.post( - endpoints.CHANNEL_MESSAGES(channelId), - { + const result = + (await rest.runMethod("post", endpoints.CHANNEL_MESSAGES(channelId), { ...content, allowed_mentions: content.mentions ? { @@ -88,8 +87,7 @@ export async function sendMessage( }, } : {}), - }, - )) as MessageCreateOptions; + })) as MessageCreateOptions; return structures.createMessageStruct(result); } diff --git a/src/helpers/messages/unpin_message.ts b/src/helpers/messages/unpin_message.ts index 499e533c7..db19544ef 100644 --- a/src/helpers/messages/unpin_message.ts +++ b/src/helpers/messages/unpin_message.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function unpin(channelId: string, messageId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.CHANNEL_PIN(channelId, messageId), ); diff --git a/src/helpers/misc/get_gateway_bot.ts b/src/helpers/misc/get_gateway_bot.ts index ca8ead1a5..1e1c94935 100644 --- a/src/helpers/misc/get_gateway_bot.ts +++ b/src/helpers/misc/get_gateway_bot.ts @@ -1,11 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ export async function getGatewayBot() { - const result = await RequestManager.get( - endpoints.GATEWAY_BOT, - ); + const result = await rest.runMethod("get", endpoints.GATEWAY_BOT); return result as DiscordBotGatewayData; } diff --git a/src/helpers/misc/get_user.ts b/src/helpers/misc/get_user.ts index de8a77eea..1b2ea2bda 100644 --- a/src/helpers/misc/get_user.ts +++ b/src/helpers/misc/get_user.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.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(userId: string) { - const result = await RequestManager.get(endpoints.USER(userId)); + const result = await rest.runMethod("get", endpoints.USER(userId)); return result as UserPayload; } diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index f6b810d8e..b8770fe9a 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -1,5 +1,5 @@ import { botId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { isHigherPosition, @@ -24,7 +24,8 @@ export async function addRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.put( + const result = await rest.runMethod( + "put", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index 07657d428..53b456a0a 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { @@ -15,7 +15,7 @@ export async function createRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.post(endpoints.GUILD_ROLES(guildId), { + const result = await rest.runMethod("post", endpoints.GUILD_ROLES(guildId), { ...options, permissions: calculateBits(options?.permissions || []), reason, diff --git a/src/helpers/roles/delete_role.ts b/src/helpers/roles/delete_role.ts index 543e12f5e..dd8c9300b 100644 --- a/src/helpers/roles/delete_role.ts +++ b/src/helpers/roles/delete_role.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function deleteRole(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.delete(endpoints.GUILD_ROLE(guildId, id)); + const result = await rest.runMethod( + "delete", + endpoints.GUILD_ROLE(guildId, id), + ); return result; } diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index 94ea6768d..c5999c63b 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -13,12 +13,16 @@ export async function editRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.patch(endpoints.GUILD_ROLE(guildId, id), { - ...options, - permissions: options.permissions - ? calculateBits(options.permissions) - : undefined, - }); + const result = await rest.runMethod( + "patch", + endpoints.GUILD_ROLE(guildId, id), + { + ...options, + permissions: options.permissions + ? calculateBits(options.permissions) + : undefined, + }, + ); return result; } diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index 4b5e8a6da..18a757cae 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -9,7 +9,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getRoles(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.get(endpoints.GUILD_ROLES(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_ROLES(guildId)); return result; } diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index e59e583c0..96462916e 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -1,5 +1,5 @@ import { botId } from "../../bot.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { isHigherPosition, @@ -26,7 +26,8 @@ export async function removeRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); diff --git a/src/helpers/roles/swap_roles.ts b/src/helpers/roles/swap_roles.ts index 37b45f067..60a2f0cf9 100644 --- a/src/helpers/roles/swap_roles.ts +++ b/src/helpers/roles/swap_roles.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function swapRoles(guildId: string, rolePositons: PositionSwap) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.GUILD_ROLES(guildId), rolePositons, ); diff --git a/src/helpers/templates/create_guild_from_template.ts b/src/helpers/templates/create_guild_from_template.ts index d6b885e98..b5be5037e 100644 --- a/src/helpers/templates/create_guild_from_template.ts +++ b/src/helpers/templates/create_guild_from_template.ts @@ -1,5 +1,5 @@ import { cacheHandlers } from "../../cache.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -21,7 +21,8 @@ export async function createGuildFromTemplate( data.icon = await urlToBase64(data.icon); } - const result = await await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.GUILD_TEMPLATE(templateCode), data, ); diff --git a/src/helpers/templates/create_guild_template.ts b/src/helpers/templates/create_guild_template.ts index 94999710c..ea3ea2718 100644 --- a/src/helpers/templates/create_guild_template.ts +++ b/src/helpers/templates/create_guild_template.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -23,10 +23,12 @@ export async function createGuildTemplate( throw new Error("The description can only be in between 0-120 characters."); } - const template = (await RequestManager.post( - endpoints.GUILD_TEMPLATES(guildId), - data, - )) as GuildTemplate; + const template = + (await rest.runMethod( + "post", + endpoints.GUILD_TEMPLATES(guildId), + data, + )) as GuildTemplate; return structures.createTemplateStruct(template); } diff --git a/src/helpers/templates/delete_guild_template.ts b/src/helpers/templates/delete_guild_template.ts index c6ecb7faf..36ab88ead 100644 --- a/src/helpers/templates/delete_guild_template.ts +++ b/src/helpers/templates/delete_guild_template.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -13,9 +13,11 @@ export async function deleteGuildTemplate( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const deletedTemplate = (await RequestManager.delete( - `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, - )) as GuildTemplate; + const deletedTemplate = + (await rest.runMethod( + "delete", + `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + )) as GuildTemplate; return structures.createTemplateStruct(deletedTemplate); } diff --git a/src/helpers/templates/edit_guild_template.ts b/src/helpers/templates/edit_guild_template.ts index b2ed01ca6..d4d458f3e 100644 --- a/src/helpers/templates/edit_guild_template.ts +++ b/src/helpers/templates/edit_guild_template.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -22,10 +22,12 @@ export async function editGuildTemplate( throw new Error("The description can only be in between 0-120 characters."); } - const template = (await RequestManager.patch( - `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, - data, - )) as GuildTemplate; + const template = + (await rest.runMethod( + "patch", + `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + data, + )) as GuildTemplate; return structures.createTemplateStruct(template); } diff --git a/src/helpers/templates/get_guild_templates.ts b/src/helpers/templates/get_guild_templates.ts index a383caea8..5c6c7bc74 100644 --- a/src/helpers/templates/get_guild_templates.ts +++ b/src/helpers/templates/get_guild_templates.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,9 +10,11 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getGuildTemplates(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const templates = (await RequestManager.get( - endpoints.GUILD_TEMPLATES(guildId), - )) as GuildTemplate[]; + const templates = + (await rest.runMethod( + "get", + endpoints.GUILD_TEMPLATES(guildId), + )) as GuildTemplate[]; return templates.map((template) => structures.createTemplateStruct(template)); } diff --git a/src/helpers/templates/get_template.ts b/src/helpers/templates/get_template.ts index b170313d3..40e73c4f8 100644 --- a/src/helpers/templates/get_template.ts +++ b/src/helpers/templates/get_template.ts @@ -1,12 +1,14 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the guild template if it exists */ export async function getTemplate(templateCode: string) { - const result = (await RequestManager.get( - endpoints.GUILD_TEMPLATE(templateCode), - ) as GuildTemplate); + const result = + (await rest.runMethod( + "get", + endpoints.GUILD_TEMPLATE(templateCode), + ) as GuildTemplate); const template = await structures.createTemplateStruct(result); return template; diff --git a/src/helpers/templates/sync_guild_template.ts b/src/helpers/templates/sync_guild_template.ts index ba02f47f0..a5fe10502 100644 --- a/src/helpers/templates/sync_guild_template.ts +++ b/src/helpers/templates/sync_guild_template.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -10,9 +10,11 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function syncGuildTemplate(guildId: string, templateCode: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const template = (await RequestManager.put( - `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, - )) as GuildTemplate; + const template = + (await rest.runMethod( + "put", + `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, + )) as GuildTemplate; return structures.createTemplateStruct(template); } diff --git a/src/helpers/webhooks/create_webhook.ts b/src/helpers/webhooks/create_webhook.ts index 7efa04e57..f94128ff8 100644 --- a/src/helpers/webhooks/create_webhook.ts +++ b/src/helpers/webhooks/create_webhook.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -24,7 +24,8 @@ export async function createWebhook( throw new Error(Errors.INVALID_WEBHOOK_NAME); } - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", endpoints.CHANNEL_WEBHOOKS(channelId), { ...options, diff --git a/src/helpers/webhooks/delete_webhook.ts b/src/helpers/webhooks/delete_webhook.ts index d92aca7e7..1ac6e95f8 100644 --- a/src/helpers/webhooks/delete_webhook.ts +++ b/src/helpers/webhooks/delete_webhook.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function deleteWebhook(channelId: string, webhookId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); - const result = await RequestManager.delete(endpoints.WEBHOOK_ID(webhookId)); + const result = await rest.runMethod( + "delete", + endpoints.WEBHOOK_ID(webhookId), + ); return result; } diff --git a/src/helpers/webhooks/delete_webhook_message.ts b/src/helpers/webhooks/delete_webhook_message.ts index b8ece8d41..61809f001 100644 --- a/src/helpers/webhooks/delete_webhook_message.ts +++ b/src/helpers/webhooks/delete_webhook_message.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; export async function deleteWebhookMessage( @@ -6,7 +6,8 @@ export async function deleteWebhookMessage( webhookToken: string, messageId: string, ) { - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId), ); diff --git a/src/helpers/webhooks/delete_webhook_with_token.ts b/src/helpers/webhooks/delete_webhook_with_token.ts index f7e8c823e..342f9d3e7 100644 --- a/src/helpers/webhooks/delete_webhook_with_token.ts +++ b/src/helpers/webhooks/delete_webhook_with_token.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Delete a webhook permanently. Returns a undefined on success */ @@ -6,7 +6,8 @@ export async function deleteWebhookWithToken( webhookId: string, webhookToken: string, ) { - const result = await RequestManager.delete( + const result = await rest.runMethod( + "delete", endpoints.WEBHOOK(webhookId, webhookToken), ); diff --git a/src/helpers/webhooks/edit_webhook.ts b/src/helpers/webhooks/edit_webhook.ts index f5ee7d59e..5b6b9afbf 100644 --- a/src/helpers/webhooks/edit_webhook.ts +++ b/src/helpers/webhooks/edit_webhook.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -10,10 +10,14 @@ export async function editWebhook( ) { await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); - const result = await RequestManager.patch(endpoints.WEBHOOK_ID(webhookId), { - ...options, - channel_id: options.channelId, - }); + const result = await rest.runMethod( + "patch", + endpoints.WEBHOOK_ID(webhookId), + { + ...options, + channel_id: options.channelId, + }, + ); return result as WebhookPayload; } diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index 4d0571803..fd68d5e4b 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -48,7 +48,8 @@ export async function editWebhookMessage( } } - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId), { ...options, allowed_mentions: options.allowed_mentions }, ) as MessageCreateOptions; diff --git a/src/helpers/webhooks/edit_webhook_with_token.ts b/src/helpers/webhooks/edit_webhook_with_token.ts index 1563f77d5..2088b740a 100644 --- a/src/helpers/webhooks/edit_webhook_with_token.ts +++ b/src/helpers/webhooks/edit_webhook_with_token.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Edit a webhook. Returns the updated webhook object on success. */ @@ -7,7 +7,8 @@ export async function editWebhookWithToken( webhookToken: string, options: Omit, ) { - const result = await RequestManager.patch( + const result = await rest.runMethod( + "patch", endpoints.WEBHOOK(webhookId, webhookToken), options, ); diff --git a/src/helpers/webhooks/execute_webhook.ts b/src/helpers/webhooks/execute_webhook.ts index 637722aa1..2a378645c 100644 --- a/src/helpers/webhooks/execute_webhook.ts +++ b/src/helpers/webhooks/execute_webhook.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { endpoints } from "../../util/constants.ts"; @@ -46,7 +46,8 @@ export async function executeWebhook( } } - const result = await RequestManager.post( + const result = await rest.runMethod( + "post", `${endpoints.WEBHOOK(webhookId, webhookToken)}${ options.wait ? "?wait=true" : "" }`, diff --git a/src/helpers/webhooks/get_webhook.ts b/src/helpers/webhooks/get_webhook.ts index a98020ab3..694afdd68 100644 --- a/src/helpers/webhooks/get_webhook.ts +++ b/src/helpers/webhooks/get_webhook.ts @@ -1,9 +1,9 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the new webhook object for the given id. */ export async function getWebhook(webhookId: string) { - const result = await RequestManager.get(endpoints.WEBHOOK_ID(webhookId)); + const result = await rest.runMethod("get", endpoints.WEBHOOK_ID(webhookId)); return result as WebhookPayload; } diff --git a/src/helpers/webhooks/get_webhook_with_token.ts b/src/helpers/webhooks/get_webhook_with_token.ts index 1bbc35218..c59ad4978 100644 --- a/src/helpers/webhooks/get_webhook_with_token.ts +++ b/src/helpers/webhooks/get_webhook_with_token.ts @@ -1,9 +1,12 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns the new webhook object for the given id, this call does not require authentication and returns no user in the webhook object. */ export async function getWebhookWithToken(webhookId: string, token: string) { - const result = await RequestManager.get(endpoints.WEBHOOK(webhookId, token)); + const result = await rest.runMethod( + "get", + endpoints.WEBHOOK(webhookId, token), + ); return result as WebhookPayload; } diff --git a/src/helpers/webhooks/get_webhooks.ts b/src/helpers/webhooks/get_webhooks.ts index dd4e08667..4a2929cd2 100644 --- a/src/helpers/webhooks/get_webhooks.ts +++ b/src/helpers/webhooks/get_webhooks.ts @@ -1,4 +1,4 @@ -import { RequestManager } from "../../rest/request_manager.ts"; +import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,7 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getWebhooks(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_WEBHOOKS"]); - const result = await RequestManager.get(endpoints.GUILD_WEBHOOKS(guildId)); + const result = await rest.runMethod("get", endpoints.GUILD_WEBHOOKS(guildId)); return result; } diff --git a/src/rest/request_manager.ts b/src/rest/request_manager.ts deleted file mode 100644 index 23319ab06..000000000 --- a/src/rest/request_manager.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { rest } from "./rest.ts"; - -export const RequestManager = { - get: (url: string, body?: unknown) => { - return rest.runMethod("get", url, body); - }, - post: (url: string, body?: unknown) => { - return rest.runMethod("post", url, body); - }, - delete: (url: string, body?: unknown) => { - return rest.runMethod("delete", url, body); - }, - patch: (url: string, body?: unknown) => { - return rest.runMethod("patch", url, body); - }, - put: (url: string, body?: unknown) => { - return rest.runMethod("put", url, body); - }, -}; diff --git a/src/rest/rest.ts b/src/rest/rest.ts index 3c058f57c..345f6b271 100644 --- a/src/rest/rest.ts +++ b/src/rest/rest.ts @@ -6,10 +6,9 @@ import { processQueue } from "./process_queue.ts"; import { processRateLimitedPaths } from "./process_rate_limited_paths.ts"; import { processRequest } from "./process_request.ts"; import { processRequestHeaders } from "./process_request_headers.ts"; -import { RequestManager } from "./request_manager.ts"; import { runMethod } from "./run_method.ts"; -export const rest: RestCache = { +export const rest = { /** The secret authorization key to confirm that this was a request made by you and not a DDOS attack. */ authorization: "discordeno_best_lib_ever", pathQueues: new Map(), @@ -30,10 +29,6 @@ export const rest: RestCache = { globallyRateLimited() {}, retriesMaxed() {}, }, - - // TODO: add propeer docs dcomments - manager: RequestManager, - /** Handler function for every request. Converts to json, verified authorization & requirements and begins processing the request */ handlePayload, checkRateLimits, diff --git a/src/util/constants.ts b/src/util/constants.ts index 90c3e99fb..2d9e6d92c 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -153,7 +153,7 @@ export const endpoints = { `${baseEndpoints.BASE_URL}/interactions/${interactionId}/${token}/callback`, INTERACTION_ORIGINAL_ID_TOKEN: (interactionId: string, token: string) => `${baseEndpoints.BASE_URL}/webhooks/${interactionId}/${token}/messages/@original`, - INTERACTION_Id_TOKEN_MESSAGEId: ( + INTERACTION_ID_TOKEN_MESSAGE_ID: ( applicationId: string, token: string, messageId: string,