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,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,
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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 },
|
||||
);
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user