fix: constant urls endpoints need to be functions

This commit is contained in:
Skillz4Killz
2022-03-25 19:23:44 +00:00
committed by GitHub
parent 18bf53ac6b
commit fbbac43053
12 changed files with 27 additions and 22 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
const result = await bot.rest.runMethod<DiscordStageInstance>( const result = await bot.rest.runMethod<DiscordStageInstance>(
bot.rest, bot.rest,
"post", "post",
bot.constants.endpoints.STAGE_INSTANCES, bot.constants.endpoints.STAGE_INSTANCES(),
{ {
channel_id: channelId.toString(), channel_id: channelId.toString(),
topic, topic,
+1 -1
View File
@@ -7,7 +7,7 @@ export async function getDiscoveryCategories(bot: Bot) {
const result = await bot.rest.runMethod<DiscordDiscoveryCategory[]>( const result = await bot.rest.runMethod<DiscordDiscoveryCategory[]>(
bot.rest, bot.rest,
"get", "get",
bot.constants.endpoints.DISCOVERY_CATEGORIES, bot.constants.endpoints.DISCOVERY_CATEGORIES(),
); );
return new Collection<number, DiscordDiscoveryCategory>( return new Collection<number, DiscordDiscoveryCategory>(
+1 -1
View File
@@ -5,7 +5,7 @@ export async function validDiscoveryTerm(bot: Bot, term: string) {
const result = await bot.rest.runMethod<DiscordValidateDiscoverySearchTerm>( const result = await bot.rest.runMethod<DiscordValidateDiscoverySearchTerm>(
bot.rest, bot.rest,
"get", "get",
bot.constants.endpoints.DISCOVERY_VALID_TERM, bot.constants.endpoints.DISCOVERY_VALID_TERM(),
{ term }, { term },
); );
+1 -1
View File
@@ -11,7 +11,7 @@ import {
/** 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. */ /** 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(bot: Bot, options: CreateGuild) { export async function createGuild(bot: Bot, options: CreateGuild) {
const result = await bot.rest.runMethod<DiscordGuild>(bot.rest, "post", bot.constants.endpoints.GUILDS, { const result = await bot.rest.runMethod<DiscordGuild>(bot.rest, "post", bot.constants.endpoints.GUILDS(), {
name: options.name, name: options.name,
afk_channel_id: options.afkChannelId, afk_channel_id: options.afkChannelId,
afk_timeout: options.afkTimeout, afk_timeout: options.afkTimeout,
+1 -1
View File
@@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts";
/** Returns an array of voice regions that can be used when creating servers. */ /** Returns an array of voice regions that can be used when creating servers. */
export async function getAvailableVoiceRegions(bot: Bot) { export async function getAvailableVoiceRegions(bot: Bot) {
const result = await bot.rest.runMethod<DiscordVoiceRegion[]>(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS); const result = await bot.rest.runMethod<DiscordVoiceRegion[]>(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS());
return new Collection( return new Collection(
result.map((region) => { result.map((region) => {
+1 -1
View File
@@ -5,7 +5,7 @@ import { DiscordChannel } from "../../types/discord.ts";
export async function getDmChannel(bot: Bot, userId: bigint) { export async function getDmChannel(bot: Bot, userId: bigint) {
if (userId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF); if (userId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF);
const dmChannelData = await bot.rest.runMethod<DiscordChannel>(bot.rest, "post", bot.constants.endpoints.USER_DM, { const dmChannelData = await bot.rest.runMethod<DiscordChannel>(bot.rest, "post", bot.constants.endpoints.USER_DM(), {
recipient_id: userId.toString(), recipient_id: userId.toString(),
}); });
+1 -1
View File
@@ -7,7 +7,7 @@ import { DiscordUser } from "../../types/discord.ts";
export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) {
const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL; const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
const result = await bot.rest.runMethod<DiscordUser>(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { const result = await bot.rest.runMethod<DiscordUser>(bot.rest, "patch", bot.constants.endpoints.USER_BOT(), {
username: options.username?.trim(), username: options.username?.trim(),
avatar, avatar,
}); });
+1 -1
View File
@@ -3,7 +3,7 @@ import { DiscordGetGatewayBot } from "../../types/discord.ts";
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
export async function getGatewayBot(bot: Bot) { export async function getGatewayBot(bot: Bot) {
const result = await bot.rest.runMethod<DiscordGetGatewayBot>(bot.rest, "get", bot.constants.endpoints.GATEWAY_BOT); const result = await bot.rest.runMethod<DiscordGetGatewayBot>(bot.rest, "get", bot.constants.endpoints.GATEWAY_BOT());
return bot.transformers.gatewayBot(result); return bot.transformers.gatewayBot(result);
} }
+1 -1
View File
@@ -6,7 +6,7 @@ export async function nitroStickerPacks(bot: Bot) {
const packs = await bot.rest.runMethod<DiscordStickerPack[]>( const packs = await bot.rest.runMethod<DiscordStickerPack[]>(
bot.rest, bot.rest,
"get", "get",
bot.constants.endpoints.NITRO_STICKER_PACKS, bot.constants.endpoints.NITRO_STICKER_PACKS(),
); );
return packs.map((pack) => bot.transformers.stickerPack(bot, pack)); return packs.map((pack) => bot.transformers.stickerPack(bot, pack));
+1 -1
View File
@@ -6,7 +6,7 @@ export async function getApplicationInfo(bot: Bot) {
const result = await bot.rest.runMethod<DiscordApplication>( const result = await bot.rest.runMethod<DiscordApplication>(
bot.rest, bot.rest,
"get", "get",
bot.constants.endpoints.OAUTH2_APPLICATION, bot.constants.endpoints.OAUTH2_APPLICATION(),
); );
return bot.transformers.application(bot, result); return bot.transformers.application(bot, result);
+5
View File
@@ -15,10 +15,15 @@ import { API_VERSION } from "../util/constants.ts";
export function createRestManager(options: CreateRestManagerOptions) { export function createRestManager(options: CreateRestManagerOptions) {
const version = options.version || API_VERSION; const version = options.version || API_VERSION;
console.log('url1', baseEndpoints.BASE_URL)
if (options.customUrl) { if (options.customUrl) {
console.log('url2', baseEndpoints.BASE_URL)
baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`; baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`;
} }
console.log('url3', baseEndpoints.BASE_URL)
return { return {
// current invalid amount // current invalid amount
invalidRequests: 0, invalidRequests: 0,
+12 -12
View File
@@ -30,7 +30,7 @@ export const endpoints = {
GUILDS_BASE, GUILDS_BASE,
CHANNEL_BASE, CHANNEL_BASE,
GATEWAY_BOT: `${baseEndpoints.BASE_URL}/gateway/bot`, GATEWAY_BOT: () => `${baseEndpoints.BASE_URL}/gateway/bot`,
// Channel Endpoints // Channel Endpoints
CHANNEL_MESSAGE: (channelId: bigint, messageId: bigint) => `${CHANNEL_BASE(channelId)}/messages/${messageId}`, CHANNEL_MESSAGE: (channelId: bigint, messageId: bigint) => `${CHANNEL_BASE(channelId)}/messages/${messageId}`,
@@ -71,7 +71,7 @@ export const endpoints = {
`${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`, `${CHANNEL_BASE(channelId)}/users/@me/threads/archived/private`,
// Guild Endpoints // Guild Endpoints
GUILDS: `${baseEndpoints.BASE_URL}/guilds`, GUILDS: () => `${baseEndpoints.BASE_URL}/guilds`,
GUILD_AUDIT_LOGS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/audit-logs`, GUILD_AUDIT_LOGS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/audit-logs`,
GUILD_BAN: (guildId: bigint, userId: bigint) => `${GUILDS_BASE(guildId)}/bans/${userId}`, GUILD_BAN: (guildId: bigint, userId: bigint) => `${GUILDS_BASE(guildId)}/bans/${userId}`,
GUILD_BANS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/bans`, GUILD_BANS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/bans`,
@@ -111,7 +111,7 @@ export const endpoints = {
`${GUILDS_BASE(guildId)}/scheduled-events/${eventId}/users`, `${GUILDS_BASE(guildId)}/scheduled-events/${eventId}/users`,
// Voice // Voice
VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`, VOICE_REGIONS: () => `${baseEndpoints.BASE_URL}/voice/regions`,
INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`, INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`,
@@ -148,30 +148,30 @@ export const endpoints = {
// User endpoints // User endpoints
USER: (userId: bigint) => `${baseEndpoints.BASE_URL}/users/${userId}`, USER: (userId: bigint) => `${baseEndpoints.BASE_URL}/users/${userId}`,
USER_BOT: `${baseEndpoints.BASE_URL}/users/@me`, USER_BOT: () => `${baseEndpoints.BASE_URL}/users/@me`,
USER_GUILDS: `${baseEndpoints.BASE_URL}/@me/guilds`, USER_GUILDS: () => `${baseEndpoints.BASE_URL}/@me/guilds`,
USER_AVATAR: (userId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/avatars/${userId}/${icon}`, USER_AVATAR: (userId: bigint, icon: string) => `${baseEndpoints.CDN_URL}/avatars/${userId}/${icon}`,
USER_DEFAULT_AVATAR: (icon: number) => `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`, USER_DEFAULT_AVATAR: (icon: number) => `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`,
USER_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`, USER_DM: () => `${baseEndpoints.BASE_URL}/users/@me/channels`,
USER_CONNECTIONS: `${baseEndpoints.BASE_URL}/users/@me/connections`, USER_CONNECTIONS: () => `${baseEndpoints.BASE_URL}/users/@me/connections`,
USER_NICK: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/@me`, USER_NICK: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/@me`,
// Discovery Endpoints // Discovery Endpoints
DISCOVERY_CATEGORIES: `${baseEndpoints.BASE_URL}/discovery/categories`, DISCOVERY_CATEGORIES: () => `${baseEndpoints.BASE_URL}/discovery/categories`,
DISCOVERY_VALID_TERM: `${baseEndpoints.BASE_URL}/discovery/valid-term`, DISCOVERY_VALID_TERM: () => `${baseEndpoints.BASE_URL}/discovery/valid-term`,
DISCOVERY_METADATA: (guildId: bigint) => `${GUILDS_BASE(guildId)}/discovery-metadata`, DISCOVERY_METADATA: (guildId: bigint) => `${GUILDS_BASE(guildId)}/discovery-metadata`,
DISCOVERY_SUBCATEGORY: (guildId: bigint, categoryId: number) => DISCOVERY_SUBCATEGORY: (guildId: bigint, categoryId: number) =>
`${GUILDS_BASE(guildId)}/discovery-categories/${categoryId}`, `${GUILDS_BASE(guildId)}/discovery-categories/${categoryId}`,
// OAuth2 // OAuth2
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`, OAUTH2_APPLICATION: () => `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
// Stage instances // Stage instances
STAGE_INSTANCES: `${baseEndpoints.BASE_URL}/stage-instances`, STAGE_INSTANCES: () => `${baseEndpoints.BASE_URL}/stage-instances`,
STAGE_INSTANCE: (channelId: bigint) => `${baseEndpoints.BASE_URL}/stage-instances/${channelId}`, STAGE_INSTANCE: (channelId: bigint) => `${baseEndpoints.BASE_URL}/stage-instances/${channelId}`,
// Misc Endpoints // Misc Endpoints
NITRO_STICKER_PACKS: `${baseEndpoints.BASE_URL}/sticker-packs`, NITRO_STICKER_PACKS: () => `${baseEndpoints.BASE_URL}/sticker-packs`,
}; };
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/; export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;