mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-15 19:08:17 +00:00
fix: constant urls endpoints need to be functions
This commit is contained in:
@@ -6,7 +6,7 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.STAGE_INSTANCES,
|
||||
bot.constants.endpoints.STAGE_INSTANCES(),
|
||||
{
|
||||
channel_id: channelId.toString(),
|
||||
topic,
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function getDiscoveryCategories(bot: Bot) {
|
||||
const result = await bot.rest.runMethod<DiscordDiscoveryCategory[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_CATEGORIES,
|
||||
bot.constants.endpoints.DISCOVERY_CATEGORIES(),
|
||||
);
|
||||
|
||||
return new Collection<number, DiscordDiscoveryCategory>(
|
||||
|
||||
@@ -5,7 +5,7 @@ export async function validDiscoveryTerm(bot: Bot, term: string) {
|
||||
const result = await bot.rest.runMethod<DiscordValidateDiscoverySearchTerm>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_VALID_TERM,
|
||||
bot.constants.endpoints.DISCOVERY_VALID_TERM(),
|
||||
{ term },
|
||||
);
|
||||
|
||||
|
||||
@@ -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. */
|
||||
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,
|
||||
afk_channel_id: options.afkChannelId,
|
||||
afk_timeout: options.afkTimeout,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts";
|
||||
|
||||
/** Returns an array of voice regions that can be used when creating servers. */
|
||||
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(
|
||||
result.map((region) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DiscordChannel } from "../../types/discord.ts";
|
||||
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);
|
||||
|
||||
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(),
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { DiscordUser } from "../../types/discord.ts";
|
||||
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 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(),
|
||||
avatar,
|
||||
});
|
||||
|
||||
@@ -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. */
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function nitroStickerPacks(bot: Bot) {
|
||||
const packs = await bot.rest.runMethod<DiscordStickerPack[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.NITRO_STICKER_PACKS,
|
||||
bot.constants.endpoints.NITRO_STICKER_PACKS(),
|
||||
);
|
||||
|
||||
return packs.map((pack) => bot.transformers.stickerPack(bot, pack));
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function getApplicationInfo(bot: Bot) {
|
||||
const result = await bot.rest.runMethod<DiscordApplication>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.OAUTH2_APPLICATION,
|
||||
bot.constants.endpoints.OAUTH2_APPLICATION(),
|
||||
);
|
||||
|
||||
return bot.transformers.application(bot, result);
|
||||
|
||||
@@ -15,10 +15,15 @@ import { API_VERSION } from "../util/constants.ts";
|
||||
export function createRestManager(options: CreateRestManagerOptions) {
|
||||
const version = options.version || API_VERSION;
|
||||
|
||||
console.log('url1', baseEndpoints.BASE_URL)
|
||||
|
||||
if (options.customUrl) {
|
||||
console.log('url2', baseEndpoints.BASE_URL)
|
||||
baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`;
|
||||
}
|
||||
|
||||
console.log('url3', baseEndpoints.BASE_URL)
|
||||
|
||||
return {
|
||||
// current invalid amount
|
||||
invalidRequests: 0,
|
||||
|
||||
+12
-12
@@ -30,7 +30,7 @@ export const endpoints = {
|
||||
GUILDS_BASE,
|
||||
CHANNEL_BASE,
|
||||
|
||||
GATEWAY_BOT: `${baseEndpoints.BASE_URL}/gateway/bot`,
|
||||
GATEWAY_BOT: () => `${baseEndpoints.BASE_URL}/gateway/bot`,
|
||||
|
||||
// Channel Endpoints
|
||||
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`,
|
||||
|
||||
// Guild Endpoints
|
||||
GUILDS: `${baseEndpoints.BASE_URL}/guilds`,
|
||||
GUILDS: () => `${baseEndpoints.BASE_URL}/guilds`,
|
||||
GUILD_AUDIT_LOGS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/audit-logs`,
|
||||
GUILD_BAN: (guildId: bigint, userId: bigint) => `${GUILDS_BASE(guildId)}/bans/${userId}`,
|
||||
GUILD_BANS: (guildId: bigint) => `${GUILDS_BASE(guildId)}/bans`,
|
||||
@@ -111,7 +111,7 @@ export const endpoints = {
|
||||
`${GUILDS_BASE(guildId)}/scheduled-events/${eventId}/users`,
|
||||
|
||||
// Voice
|
||||
VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`,
|
||||
VOICE_REGIONS: () => `${baseEndpoints.BASE_URL}/voice/regions`,
|
||||
|
||||
INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`,
|
||||
|
||||
@@ -148,30 +148,30 @@ export const endpoints = {
|
||||
|
||||
// User endpoints
|
||||
USER: (userId: bigint) => `${baseEndpoints.BASE_URL}/users/${userId}`,
|
||||
USER_BOT: `${baseEndpoints.BASE_URL}/users/@me`,
|
||||
USER_GUILDS: `${baseEndpoints.BASE_URL}/@me/guilds`,
|
||||
USER_BOT: () => `${baseEndpoints.BASE_URL}/users/@me`,
|
||||
USER_GUILDS: () => `${baseEndpoints.BASE_URL}/@me/guilds`,
|
||||
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_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`,
|
||||
USER_CONNECTIONS: `${baseEndpoints.BASE_URL}/users/@me/connections`,
|
||||
USER_DM: () => `${baseEndpoints.BASE_URL}/users/@me/channels`,
|
||||
USER_CONNECTIONS: () => `${baseEndpoints.BASE_URL}/users/@me/connections`,
|
||||
USER_NICK: (guildId: bigint) => `${GUILDS_BASE(guildId)}/members/@me`,
|
||||
|
||||
// Discovery Endpoints
|
||||
DISCOVERY_CATEGORIES: `${baseEndpoints.BASE_URL}/discovery/categories`,
|
||||
DISCOVERY_VALID_TERM: `${baseEndpoints.BASE_URL}/discovery/valid-term`,
|
||||
DISCOVERY_CATEGORIES: () => `${baseEndpoints.BASE_URL}/discovery/categories`,
|
||||
DISCOVERY_VALID_TERM: () => `${baseEndpoints.BASE_URL}/discovery/valid-term`,
|
||||
DISCOVERY_METADATA: (guildId: bigint) => `${GUILDS_BASE(guildId)}/discovery-metadata`,
|
||||
DISCOVERY_SUBCATEGORY: (guildId: bigint, categoryId: number) =>
|
||||
`${GUILDS_BASE(guildId)}/discovery-categories/${categoryId}`,
|
||||
|
||||
// OAuth2
|
||||
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
|
||||
OAUTH2_APPLICATION: () => `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
|
||||
|
||||
// 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}`,
|
||||
|
||||
// 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}$/;
|
||||
|
||||
Reference in New Issue
Block a user