refactor: remove RequestManager and use runMethod() (#732)

* fix(rest/process_request): use DiscordHTTPResponseCodes

* refactor: remove RequestManager

* refactor: remove RequestManager and use runMethod()
This commit is contained in:
ayntee
2021-04-02 23:18:51 +04:00
committed by GitHub
parent ec9ceaab04
commit 5f1b82a4e8
106 changed files with 418 additions and 326 deletions
+3 -2
View File
@@ -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),
+4 -3
View File
@@ -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),
);
}
@@ -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,
+3 -2
View File
@@ -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),
+3 -2
View File
@@ -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),
+8 -6
View File
@@ -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]));
}
@@ -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,
);
+3 -2
View File
@@ -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),
@@ -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),