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

View File

@@ -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);

View File

@@ -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 },
);

View File

@@ -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),
);

View File

@@ -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;
}

View File

@@ -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),

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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),
);

View File

@@ -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);

View File

@@ -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)),

View File

@@ -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;
}

View File

@@ -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,
);

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),

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),
);
}

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";
/** 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,

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),

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),

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]));
}

View File

@@ -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,
);

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),

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";
@@ -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),

View File

@@ -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,

View File

@@ -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 },
);

View File

@@ -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,

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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,
);

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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),
);

View File

@@ -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<string, BannedUser>(
results.map((res) => [res.user.id, res]),

View File

@@ -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,
});

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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`);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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),
);

View File

@@ -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,
);

View File

@@ -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),
);

View File

@@ -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),
);

View File

@@ -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,
);

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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,
});

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) => {

View File

@@ -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 },
);

View File

@@ -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),
);

View File

@@ -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,
);

View File

@@ -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;
}

View File

@@ -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),
);

View File

@@ -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 },
);

View File

@@ -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),

View File

@@ -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,
);

View File

@@ -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);
}

View File

@@ -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)),

View File

@@ -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]));
}

View File

@@ -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),
);

View File

@@ -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);
}

View File

@@ -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),
);

View File

@@ -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),
);

View File

@@ -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),
);

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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),
);

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 },
);

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 },
);

View File

@@ -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,
);

View File

@@ -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,
);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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),
);

View File

@@ -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),
);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<WebhookEditOptions, "channelId">,
) {
const result = await RequestManager.patch(
const result = await rest.runMethod(
"patch",
endpoints.WEBHOOK(webhookId, webhookToken),
options,
);

View File

@@ -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" : ""
}`,

Some files were not shown because too many files have changed in this diff Show More