mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +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 { 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);
|
||||
|
||||
@@ -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 },
|
||||
);
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user