diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/commands/batch_edit_slash_command_permissions.ts new file mode 100644 index 000000000..514b546b7 --- /dev/null +++ b/src/helpers/commands/batch_edit_slash_command_permissions.ts @@ -0,0 +1,17 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; +import { endpoints } from "../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; + +/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */ +export async function batchEditSlashCommandPermissions( + guildId: string, + options: { id: string; permissions: ApplicationCommandPermissions[] }[], +) { + return await rest.runMethod( + "put", + endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), + camelKeysToSnakeCase(options), + ); +} diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/commands/create_slash_command.ts index 2da719f56..c756570e5 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/commands/create_slash_command.ts @@ -21,7 +21,7 @@ import { */ export async function createSlashCommand( options: CreateGlobalApplicationCommand, - guildId: string, + guildId?: string, ) { validateSlashCommands([options], true); diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts new file mode 100644 index 000000000..1ea764d8a --- /dev/null +++ b/src/helpers/commands/edit_slash_command_permissions.ts @@ -0,0 +1,18 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; +import { endpoints } from "../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; + +/** Edits command permissions for a specific command for your application in a guild. */ +export async function editSlashCommandPermissions( + guildId: string, + commandId: string, + options: ApplicationCommandPermissions[], +) { + return await rest.runMethod( + "put", + endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), + { permissions: camelKeysToSnakeCase(options) }, + ); +} diff --git a/src/helpers/commands/get_slash_command_permission.ts b/src/helpers/commands/get_slash_command_permission.ts new file mode 100644 index 000000000..f34362b9f --- /dev/null +++ b/src/helpers/commands/get_slash_command_permission.ts @@ -0,0 +1,15 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ +export async function getSlashCommandPermission( + guildId: string, + commandId: string, +) { + return await rest.runMethod( + "get", + endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), + ); +} diff --git a/src/helpers/commands/get_slash_command_permissions.ts b/src/helpers/commands/get_slash_command_permissions.ts new file mode 100644 index 000000000..4d69204bf --- /dev/null +++ b/src/helpers/commands/get_slash_command_permissions.ts @@ -0,0 +1,12 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ +export async function getSlashCommandPermissions(guildId: string) { + return await rest.runMethod( + "get", + endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), + ); +} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 22799a964..71a16d577 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,15 +13,24 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; +import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; import { createSlashCommand } from "./commands/create_slash_command.ts"; import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; import { deleteSlashResponse } from "./commands/delete_slash_response.ts"; +import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts"; import { editSlashResponse } from "./commands/edit_slash_response.ts"; import { getSlashCommand } from "./commands/get_slash_command.ts"; import { getSlashCommands } from "./commands/get_slash_commands.ts"; +import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; +import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts"; import { sendInteractionResponse } from "./commands/send_interaction_response.ts"; import { upsertSlashCommand } from "./commands/upsert_slash_command.ts"; import { upsertSlashCommands } from "./commands/upsert_slash_commands.ts"; +import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts"; +import { editDiscovery } from "./discovery/edit_discovery.ts"; +import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts"; +import { removeDiscoverySubcategory } from "./discovery/remove_discovery_subcategory.ts"; +import { validDiscoveryTerm } from "./discovery/valid_discovery_term.ts"; import { createEmoji } from "./emojis/create_emoji.ts"; import { deleteEmoji } from "./emojis/delete_emoji.ts"; import { editEmoji } from "./emojis/edit_emoji.ts"; @@ -115,11 +124,6 @@ import { executeWebhook } from "./webhooks/execute_webhook.ts"; import { getWebhook } from "./webhooks/get_webhook.ts"; import { getWebhooks } from "./webhooks/get_webhooks.ts"; import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts"; -import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts"; -import { editDiscovery } from "./discovery/edit_discovery.ts"; -import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts"; -import { removeDiscoverySubcategory } from "./discovery/remove_discovery_subcategory.ts"; -import { validDiscoveryTerm } from "./discovery/valid_discovery_term.ts"; export { addDiscoverySubcategory, @@ -129,6 +133,7 @@ export { avatarURL, ban, banMember, + batchEditSlashCommandPermissions, categoryChildren, channelOverwriteHasPermission, createChannel, @@ -206,6 +211,8 @@ export { getReactions, getRoles, getSlashCommand, + getSlashCommandPermission, + getSlashCommandPermissions, getSlashCommands, getTemplate, getUser, @@ -272,6 +279,10 @@ export let helpers = { deleteSlashCommand, deleteSlashResponse, editSlashResponse, + getSlashCommandPermission, + getSlashCommandPermissions, + batchEditSlashCommandPermissions, + editSlashCommandPermissions, sendInteractionResponse, getSlashCommand, getSlashCommands, diff --git a/src/util/constants.ts b/src/util/constants.ts index e241097b0..eed6df6f1 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -148,6 +148,16 @@ export const endpoints = { `${baseEndpoints.BASE_URL}/applications/${applicationId}/commands`, COMMANDS_GUILD: (applicationId: string, guildId: string) => `${baseEndpoints.BASE_URL}/applications/${applicationId}/guilds/${guildId}/commands`, + COMMANDS_PERMISSIONS: (applicationId: string, guildId: string) => + `${endpoints.COMMANDS_GUILD(applicationId, guildId)}/permissions`, + COMMANDS_PERMISSION: ( + applicationId: string, + guildId: string, + commandId: string, + ) => + `${ + endpoints.COMMANDS_GUILD(applicationId, guildId) + }/${commandId}/permissions`, COMMANDS_ID: (applicationId: string, commandId: string) => `${baseEndpoints.BASE_URL}/applications/${applicationId}/commands/${commandId}`, COMMANDS_GUILD_ID: (