From f2ae9db4a467833a587ed3388347bfd24a6f9dee Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:34:28 +0200 Subject: [PATCH 01/12] add application command permissions endpoint --- src/util/constants.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/constants.ts b/src/util/constants.ts index e241097b0..2d188c57e 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -148,6 +148,8 @@ 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_ID: (applicationId: string, commandId: string) => `${baseEndpoints.BASE_URL}/applications/${applicationId}/commands/${commandId}`, COMMANDS_GUILD_ID: ( From 9fa6afa0574431bb69d69aa510db601217fa2ae3 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 22 Apr 2021 21:34:30 +0200 Subject: [PATCH 02/12] Create get_slash_command_permissions.ts --- .../commands/get_slash_command_permissions.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/helpers/commands/get_slash_command_permissions.ts 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), + ); +} From 7a085f1cd65538f40f8a8d597a7f61350d3f67fe Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 18:22:44 +0200 Subject: [PATCH 03/12] Update create_slash_command.ts --- src/helpers/commands/create_slash_command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From ef7ae71f05fbaf693d1e64a6c0f644d20b101373 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 25 Apr 2021 16:32:04 +0200 Subject: [PATCH 04/12] Create edit_slash_command_permissions.ts --- .../commands/edit_slash_command_permissions.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/helpers/commands/edit_slash_command_permissions.ts 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..5617f3a9d --- /dev/null +++ b/src/helpers/commands/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"; + +/** 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), + options, + ); +} From 79c236dde569125ab18dd947bbe9ec09afad0a1f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 25 Apr 2021 16:33:03 +0100 Subject: [PATCH 05/12] Create get_slash_command_permission.ts --- .../commands/get_slash_command_permission.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/helpers/commands/get_slash_command_permission.ts 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), + ); +} From ae1361c31ed0cd97be1eacc18650d871d2e27a65 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 26 Apr 2021 20:23:56 +0100 Subject: [PATCH 06/12] Create batch_edit_slash_command_permissions.ts --- .../batch_edit_slash_command_permissions.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/helpers/commands/batch_edit_slash_command_permissions.ts 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..cf1adfa46 --- /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 { snakeKeysToCamelCase } 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), + snakeKeysToCamelCase(options), + ); +} From 04b585c73916992bd502a03faef1eb51798bed95 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:05:46 +0200 Subject: [PATCH 07/12] fix buggs --- src/helpers/commands/edit_slash_command_permissions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts index 5617f3a9d..1ea764d8a 100644 --- a/src/helpers/commands/edit_slash_command_permissions.ts +++ b/src/helpers/commands/edit_slash_command_permissions.ts @@ -2,6 +2,7 @@ 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( @@ -12,6 +13,6 @@ export async function editSlashCommandPermissions( return await rest.runMethod( "put", endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), - options, + { permissions: camelKeysToSnakeCase(options) }, ); } From 32cb0dfdcc88939b52459785c4e18cc57edd0f6a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:05:53 +0200 Subject: [PATCH 08/12] Update constants.ts --- src/util/constants.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util/constants.ts b/src/util/constants.ts index 2d188c57e..eed6df6f1 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -150,6 +150,14 @@ export const endpoints = { `${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: ( From 37de4b3922a226d0205c5aa6ba3ead509e001c01 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:12:59 +0200 Subject: [PATCH 09/12] Update mod.ts --- src/helpers/mod.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 22799a964..f4e539e79 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -120,6 +120,8 @@ 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 { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; +import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts"; export { addDiscoverySubcategory, @@ -206,6 +208,8 @@ export { getReactions, getRoles, getSlashCommand, + getSlashCommandPermission, + getSlashCommandPermissions, getSlashCommands, getTemplate, getUser, @@ -272,6 +276,8 @@ export let helpers = { deleteSlashCommand, deleteSlashResponse, editSlashResponse, + getSlashCommandPermission, + getSlashCommandPermissions, sendInteractionResponse, getSlashCommand, getSlashCommands, From d244d83a6a87525c7f60d0078a13aa5494b9371a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:22:23 +0200 Subject: [PATCH 10/12] Update mod.ts --- src/helpers/mod.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index f4e539e79..9e952dd81 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -16,12 +16,20 @@ import { swapChannels } from "./channels/swap_channels.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,13 +123,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"; -import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; -import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts"; export { addDiscoverySubcategory, @@ -278,6 +279,9 @@ export let helpers = { editSlashResponse, getSlashCommandPermission, getSlashCommandPermissions, + batchEditSlashCommandPermissions, + editSlashCommandPermissions, + editSlashCommandPermission, sendInteractionResponse, getSlashCommand, getSlashCommands, From 7e5176aa3ad949fe8dc5075b0bcf189226d14e34 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:34:21 +0200 Subject: [PATCH 11/12] Update mod.ts --- src/helpers/mod.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 9e952dd81..71a16d577 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,6 +13,7 @@ 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"; @@ -132,6 +133,7 @@ export { avatarURL, ban, banMember, + batchEditSlashCommandPermissions, categoryChildren, channelOverwriteHasPermission, createChannel, @@ -281,7 +283,6 @@ export let helpers = { getSlashCommandPermissions, batchEditSlashCommandPermissions, editSlashCommandPermissions, - editSlashCommandPermission, sendInteractionResponse, getSlashCommand, getSlashCommands, From a84ede2a001725d6e3ff32db678e1ddb91944fad Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 29 Apr 2021 09:04:02 +0200 Subject: [PATCH 12/12] wrong converter --- src/helpers/commands/batch_edit_slash_command_permissions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/commands/batch_edit_slash_command_permissions.ts index cf1adfa46..514b546b7 100644 --- a/src/helpers/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/commands/batch_edit_slash_command_permissions.ts @@ -2,7 +2,7 @@ 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 { snakeKeysToCamelCase } from "../../util/utils.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( @@ -12,6 +12,6 @@ export async function batchEditSlashCommandPermissions( return await rest.runMethod( "put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), - snakeKeysToCamelCase(options), + camelKeysToSnakeCase(options), ); }