mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-17 19:58:18 +00:00
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:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user