diff --git a/src/api/handlers/channel.ts b/src/api/handlers/channel.ts index f0f8266e2..f24709d36 100644 --- a/src/api/handlers/channel.ts +++ b/src/api/handlers/channel.ts @@ -417,7 +417,7 @@ export async function editChannel( }; return RequestManager.patch( - endpoints.GUILD_CHANNEL(channelID), + endpoints.CHANNEL_BASE(channelID), { ...payload, reason, diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index d27223270..25ee6b243 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -52,7 +52,7 @@ export async function createServer(options: CreateServerOptions) { /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ export function deleteServer(guildID: string) { - return RequestManager.delete(endpoints.GUILD(guildID)); + return RequestManager.delete(endpoints.GUILDS_BASE(guildID)); } /** Gets an array of all the channels ids that are the children of this category. */ @@ -148,7 +148,7 @@ export async function deleteChannel( throw new Error(Errors.MISSING_MANAGE_CHANNELS); } - return RequestManager.delete(endpoints.CHANNEL(channelID), { reason }); + return RequestManager.delete(endpoints.CHANNEL_BASE(channelID), { reason }); } /** Returns a list of guild channel objects. @@ -174,7 +174,7 @@ export async function getChannels(guildID: string, addToCache = true) { */ export async function getChannel(channelID: string, addToCache = true) { const result = await RequestManager.get( - endpoints.GUILD_CHANNEL(channelID), + endpoints.CHANNEL_BASE(channelID), ) as ChannelCreatePayload; const channel = await structures.createChannel(result, result.guild_id); if (addToCache) await cacheHandlers.set("channels", channel.id, channel); @@ -462,7 +462,7 @@ export async function getEmbed(guildID: string) { throw new Error(Errors.MISSING_MANAGE_GUILD); } - return RequestManager.get(endpoints.GUILD_EMBED(guildID)); + return RequestManager.get(endpoints.GUILD_WIDGET(guildID)); } /** Modify a guild embed object for the guild. Requires the MANAGE_GUILD permission. */ @@ -477,7 +477,7 @@ export async function editEmbed( } return RequestManager.patch( - endpoints.GUILD_EMBED(guildID), + endpoints.GUILD_WIDGET(guildID), { enabled, channel_id: channelID }, ); } @@ -603,7 +603,7 @@ export async function editGuild(guildID: string, options: GuildEditOptions) { options.splash = await urlToBase64(options.splash); } - return RequestManager.patch(endpoints.GUILD(guildID), options); + return RequestManager.patch(endpoints.GUILDS_BASE(guildID), options); } /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ @@ -653,7 +653,7 @@ export function getUser(userID: string) { * */ export function getGuild(guildID: string, counts = true) { return RequestManager.get( - endpoints.GUILD(guildID), + endpoints.GUILDS_BASE(guildID), { with_counts: counts }, ) as Promise; } diff --git a/src/api/handlers/member.ts b/src/api/handlers/member.ts index ec94c4b08..29da6a084 100644 --- a/src/api/handlers/member.ts +++ b/src/api/handlers/member.ts @@ -124,7 +124,7 @@ export async function sendDirectMessage( if (!dmChannel) { // If not available in cache create a new one. const dmChannelData = await RequestManager.post( - endpoints.USER_CREATE_DM, + endpoints.USER_DM, { recipient_id: memberID }, ) as DMChannelCreatePayload; // Channel create event will have added this channel to the cache diff --git a/src/api/handlers/webhook.ts b/src/api/handlers/webhook.ts index 2461645cb..12213c0ba 100644 --- a/src/api/handlers/webhook.ts +++ b/src/api/handlers/webhook.ts @@ -1,4 +1,5 @@ import { botID } from "../../bot.ts"; +import { RequestManager } from "../../rest/request_manager.ts"; import { CreateSlashCommandOptions, EditSlashCommandOptions, @@ -17,7 +18,6 @@ import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; import { structures } from "../structures/mod.ts"; -import { RequestManager } from "../../rest/request_manager.ts"; /** Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations: * @@ -166,7 +166,7 @@ export function editWebhookMessage( } return RequestManager.patch( - endpoints.WEBHOOK_EDIT(webhookID, webhookToken, messageID), + endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken, messageID), { ...options, allowed_mentions: options.allowed_mentions }, ); } @@ -177,7 +177,7 @@ export function deleteWebhookMessage( messageID: string, ) { return RequestManager.delete( - endpoints.WEBHOOK_DELETE(webhookID, webhookToken, messageID), + endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken, messageID), ); } diff --git a/src/util/constants.ts b/src/util/constants.ts index d7033f499..369bde671 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -20,127 +20,150 @@ export const baseEndpoints = { CDN_URL: IMAGE_BASE_URL, }; -const GUILDS_BASE = (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}`; +const GUILDS_BASE = (guildID: string) => + `${baseEndpoints.BASE_URL}/guilds/${guildID}`; +const CHANNEL_BASE = (channelID: string) => + `${baseEndpoints.BASE_URL}/channels/${channelID}`; export const endpoints = { + GUILDS_BASE, + CHANNEL_BASE, + GATEWAY_BOT: `${baseEndpoints.BASE_URL}/gateway/bot`, // Channel Endpoints - CHANNEL: (id: string) => `${baseEndpoints.BASE_URL}/channels/${id}`, - CHANNEL_MESSAGE: (id: string, messageID: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}`, - CHANNEL_MESSAGES: (id: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages`, + CHANNEL_MESSAGE: (channelID: string, messageID: string) => + `${CHANNEL_BASE(channelID)}/messages/${messageID}`, + CHANNEL_MESSAGES: (channelID: string) => + `${CHANNEL_BASE(channelID)}/messages`, CHANNEL_PIN: (channelID: string, messageID: string) => - `${baseEndpoints.BASE_URL}/channels/${channelID}/pins/${messageID}`, - CHANNEL_PINS: (id: string) => `${baseEndpoints.BASE_URL}/channels/${id}/pins`, - CHANNEL_BULK_DELETE: (id: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/bulk-delete`, - CHANNEL_INVITES: (id: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/invites`, - CHANNEL_WEBHOOKS: (id: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/webhooks`, + `${CHANNEL_BASE(channelID)}/pins/${messageID}`, + CHANNEL_PINS: (channelID: string) => `${CHANNEL_BASE(channelID)}/pins`, + CHANNEL_BULK_DELETE: (channelID: string) => + `${CHANNEL_BASE(channelID)}/messages/bulk-delete`, + CHANNEL_INVITES: (channelID: string) => `${CHANNEL_BASE(channelID)}/invites`, + CHANNEL_WEBHOOKS: (channelID: string) => + `${CHANNEL_BASE(channelID)}/webhooks`, CHANNEL_MESSAGE_REACTION_ME: ( - id: string, + channelID: string, messageID: string, emoji: string, ) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions/${emoji}/@me`, + `${CHANNEL_BASE(channelID)}/messages/${messageID}/reactions/${emoji}/@me`, CHANNEL_MESSAGE_REACTION_USER: ( - id: string, + channelID: string, messageID: string, emoji: string, userId: string, ) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions/${emoji}/${userId}`, - CHANNEL_MESSAGE_REACTIONS: (id: string, messageID: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions`, - CHANNEL_MESSAGE_REACTION: (id: string, messageID: string, emoji: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions/${emoji}`, - CHANNEL_FOLLOW: (id: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/followers`, - CHANNEL_MESSAGE_CROSSPOST: (id: string, messageID: string) => - `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/crosspost`, + `${ + CHANNEL_BASE(channelID) + }/messages/${messageID}/reactions/${emoji}/${userId}`, + CHANNEL_MESSAGE_REACTIONS: (channelID: string, messageID: string) => + `${CHANNEL_BASE(channelID)}/messages/${messageID}/reactions`, + CHANNEL_MESSAGE_REACTION: ( + channelID: string, + messageID: string, + emoji: string, + ) => `${CHANNEL_BASE(channelID)}/messages/${messageID}/reactions/${emoji}`, + CHANNEL_FOLLOW: (channelID: string) => `${CHANNEL_BASE(channelID)}/followers`, + CHANNEL_MESSAGE_CROSSPOST: (channelID: string, messageID: string) => + `${CHANNEL_BASE(channelID)}/messages/${messageID}/crosspost`, + CHANNEL_OVERWRITE: (channelID: string, overwriteID: string) => + `${CHANNEL_BASE(channelID)}/permissions/${overwriteID}`, + // Bots SHALL NOT use this endpoint but they can + CHANNEL_TYPING: (channelID: string) => `${CHANNEL_BASE(channelID)}/typing`, // Guild Endpoints GUILDS: `${baseEndpoints.BASE_URL}/guilds`, - GUILD: (id: string) => `${GUILDS_BASE(id)}`, - GUILD_AUDIT_LOGS: (id: string) => `${GUILDS_BASE(id)}/audit-logs`, - GUILD_BAN: (id: string, userID: string) => - `${GUILDS_BASE(id)}/bans/${userID}`, - GUILD_BANS: (id: string) => `${GUILDS_BASE(id)}/bans`, - GUILD_BANNER: (id: string, icon: string) => - `${baseEndpoints.CDN_URL}/banners/${id}/${icon}`, - GUILD_CHANNELS: (id: string) => `${GUILDS_BASE(id)}/channels`, - GUILD_CHANNEL: (id: string) => `${baseEndpoints.BASE_URL}/channels/${id}`, - GUILD_EMBED: (id: string) => `${GUILDS_BASE(id)}/widget`, - GUILD_EMOJI: (id: string, emoji_id: string) => - `${GUILDS_BASE(id)}/emojis/${emoji_id}`, - GUILD_EMOJIS: (id: string) => `${GUILDS_BASE(id)}/emojis`, - GUILD_ICON: (id: string, icon: string) => - `${baseEndpoints.CDN_URL}/icons/${id}/${icon}`, - GUILD_INTEGRATION: (id: string, integrationID: string) => - `${GUILDS_BASE(id)}/integrations/${integrationID}`, - GUILD_INTEGRATION_SYNC: (id: string, integrationID: string) => - `${GUILDS_BASE(id)}/integrations/${integrationID}/sync`, - GUILD_INTEGRATIONS: (id: string) => - `${GUILDS_BASE(id)}/integrations?include_applications=true`, - GUILD_INVITES: (id: string) => `${GUILDS_BASE(id)}/invites`, - GUILD_LEAVE: (id: string) => - `${baseEndpoints.BASE_URL}/users/@me/guilds/${id}`, - GUILD_MEMBER: (id: string, memberID: string) => - `${GUILDS_BASE(id)}/members/${memberID}`, - GUILD_MEMBER_ROLE: (id: string, memberID: string, roleID: string) => - `${GUILDS_BASE(id)}/members/${memberID}/roles/${roleID}`, - GUILD_PRUNE: (id: string) => `${GUILDS_BASE(id)}/prune`, - GUILD_REGIONS: (id: string) => `${GUILDS_BASE(id)}/regions`, - GUILD_ROLE: (id: string, roleID: string) => - `${GUILDS_BASE(id)}/roles/${roleID}`, - GUILD_ROLES: (id: string) => `${GUILDS_BASE(id)}/roles`, - GUILD_SPLASH: (id: string, icon: string) => - `${baseEndpoints.CDN_URL}/splashes/${id}/${icon}`, - GUILD_VANITY_URL: (id: string) => `${GUILDS_BASE(id)}/vanity-url`, - GUILD_WEBHOOKS: (id: string) => `${GUILDS_BASE(id)}/webhooks`, + GUILD_AUDIT_LOGS: (guildID: string) => `${GUILDS_BASE(guildID)}/audit-logs`, + GUILD_BAN: (guildID: string, userID: string) => + `${GUILDS_BASE(guildID)}/bans/${userID}`, + GUILD_BANS: (guildID: string) => `${GUILDS_BASE(guildID)}/bans`, + GUILD_BANNER: (guildID: string, icon: string) => + `${baseEndpoints.CDN_URL}/banners/${guildID}/${icon}`, + GUILD_CHANNELS: (guildID: string) => `${GUILDS_BASE(guildID)}/channels`, + GUILD_WIDGET: (guildID: string) => `${GUILDS_BASE(guildID)}/widget`, + GUILD_EMOJI: (guildID: string, emojiID: string) => + `${GUILDS_BASE(guildID)}/emojis/${emojiID}`, + GUILD_EMOJIS: (guildID: string) => `${GUILDS_BASE(guildID)}/emojis`, + GUILD_ICON: (guildID: string, icon: string) => + `${baseEndpoints.CDN_URL}/icons/${guildID}/${icon}`, + GUILD_INTEGRATION: (guildID: string, integrationID: string) => + `${GUILDS_BASE(guildID)}/integrations/${integrationID}`, + GUILD_INTEGRATION_SYNC: (guildID: string, integrationID: string) => + `${GUILDS_BASE(guildID)}/integrations/${integrationID}/sync`, + GUILD_INTEGRATIONS: (guildID: string) => + `${GUILDS_BASE(guildID)}/integrations?include_applications=true`, + GUILD_INTEGRATION_CREATE: (guildID: string) => + `${GUILDS_BASE(guildID)}/integrations`, + GUILD_INVITES: (guildID: string) => `${GUILDS_BASE(guildID)}/invites`, + GUILD_LEAVE: (guildID: string) => + `${baseEndpoints.BASE_URL}/users/@me/guilds/${guildID}`, + GUILD_MEMBER: (guildID: string, userID: string) => + `${GUILDS_BASE(guildID)}/members/${userID}`, + GUILD_MEMBERS: (guildID: string) => `${GUILDS_BASE(guildID)}/members`, + GUILD_MEMBER_ROLE: (guildID: string, memberID: string, roleID: string) => + `${GUILDS_BASE(guildID)}/members/${memberID}/roles/${roleID}`, + GUILD_PRUNE: (guildID: string) => `${GUILDS_BASE(guildID)}/prune`, + GUILD_REGIONS: (guildID: string) => `${GUILDS_BASE(guildID)}/regions`, + GUILD_ROLE: (guildID: string, roleID: string) => + `${GUILDS_BASE(guildID)}/roles/${roleID}`, + GUILD_ROLES: (guildID: string) => `${GUILDS_BASE(guildID)}/roles`, + GUILD_SPLASH: (guildID: string, icon: string) => + `${baseEndpoints.CDN_URL}/splashes/${guildID}/${icon}`, + GUILD_VANITY_URL: (guildID: string) => `${GUILDS_BASE(guildID)}/vanity-url`, + GUILD_WEBHOOKS: (guildID: string) => `${GUILDS_BASE(guildID)}/webhooks`, GUILD_TEMPLATE: (code: string) => `${baseEndpoints.BASE_URL}/guilds/templates/${code}`, - GUILD_TEMPLATES: (id: string) => `${GUILDS_BASE(id)}/templates`, + GUILD_TEMPLATES: (guildID: string) => `${GUILDS_BASE(guildID)}/templates`, + GUILD_PREVIEW: (guildID: string) => `${GUILDS_BASE(guildID)}/preview`, - WEBHOOK: (id: string, token: string) => - `${baseEndpoints.BASE_URL}/webhooks/${id}/${token}`, - WEBHOOK_ID: (id: string) => `${baseEndpoints.BASE_URL}/webhooks/${id}`, - WEBHOOK_EDIT: (id: string, token: string, messageID: string) => - `${baseEndpoints.BASE_URL}/webhooks/${id}/${token}/messages/${messageID}`, - WEBHOOK_DELETE: (id: string, token: string, messageID: string) => - `${baseEndpoints.BASE_URL}/webhooks/${id}/${token}/messages/${messageID}`, + INVITE: (inviteCode: string) => + `${baseEndpoints.BASE_URL}/invites/${inviteCode}`, + + WEBHOOK: (webhookID: string, token: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookID}/${token}`, + WEBHOOK_ID: (webhookID: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookID}`, + WEBHOOK_MESSAGE: (webhookID: string, token: string, messageID: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookID}/${token}/messages/${messageID}`, + WEBHOOK_SLACK: (webhookID: string, token: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookID}/${token}/slack`, + WEBHOOK_GITHUB: (webhookID: string, token: string) => + `${baseEndpoints.BASE_URL}/webhooks/${webhookID}/${token}/github`, // Application Endpoints COMMANDS: (botID: string) => `${baseEndpoints.BASE_URL}/applications/${botID}/commands`, - COMMANDS_GUILD: (botID: string, id: string) => - `${baseEndpoints.BASE_URL}/applications/${botID}/guilds/${id}/commands`, - COMMANDS_ID: (botID: string, id: string) => - `${baseEndpoints.BASE_URL}/applications/${botID}/commands/${id}`, - COMMANDS_GUILD_ID: (botID: string, id: string, guildID: string) => - `${baseEndpoints.BASE_URL}/applications/${botID}/guilds/${guildID}/commands/${id}`, + COMMANDS_GUILD: (botID: string, guildID: string) => + `${baseEndpoints.BASE_URL}/applications/${botID}/guilds/${guildID}/commands`, + COMMANDS_ID: (botID: string, commandID: string) => + `${baseEndpoints.BASE_URL}/applications/${botID}/commands/${commandID}`, + COMMANDS_GUILD_ID: (botID: string, commandID: string, guildID: string) => + `${baseEndpoints.BASE_URL}/applications/${botID}/guilds/${guildID}/commands/${commandID}`, // Interaction Endpoints - INTERACTION_ID_TOKEN: (id: string, token: string) => - `${baseEndpoints.BASE_URL}/interactions/${id}/${token}/callback`, - INTERACTION_ORIGINAL_ID_TOKEN: (id: string, token: string) => - `${baseEndpoints.BASE_URL}/webhooks/${id}/${token}/messages/@original`, + INTERACTION_ID_TOKEN: (interactionID: string, token: string) => + `${baseEndpoints.BASE_URL}/interactions/${interactionID}/${token}/callback`, + INTERACTION_ORIGINAL_ID_TOKEN: (interactionID: string, token: string) => + `${baseEndpoints.BASE_URL}/webhooks/${interactionID}/${token}/messages/@original`, INTERACTION_ID_TOKEN_MESSAGEID: ( - id: string, + applicationID: string, token: string, messageID: string, ) => - `${baseEndpoints.BASE_URL}/webhooks/${id}/${token}/messages/${messageID}`, + `${baseEndpoints.BASE_URL}/webhooks/${applicationID}/${token}/messages/${messageID}`, // User endpoints - USER: (id: string) => `${baseEndpoints.BASE_URL}/users/${id}`, + USER: (userID: string) => `${baseEndpoints.BASE_URL}/users/${userID}`, USER_BOT: `${baseEndpoints.BASE_URL}/users/@me`, - USER_AVATAR: (id: string, icon: string) => - `${baseEndpoints.CDN_URL}/avatars/${id}/${icon}`, + USER_GUILDS: `${baseEndpoints.BASE_URL}/@me/guilds`, + USER_AVATAR: (userID: string, icon: string) => + `${baseEndpoints.CDN_URL}/avatars/${userID}/${icon}`, USER_DEFAULT_AVATAR: (icon: number) => `${baseEndpoints.CDN_URL}/embed/avatars/${icon}.png`, - USER_CREATE_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`, + USER_DM: `${baseEndpoints.BASE_URL}/users/@me/channels`, + USER_CONNECTIONS: `${baseEndpoints.BASE_URL}/users/@me/connections`, + USER_NICK: (guildID: string) => `${GUILDS_BASE(guildID)}/members/@me/nick`, };