diff --git a/src/bot.ts b/src/bot.ts index d66717fe5..f538e0da1 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -110,6 +110,7 @@ import { AsyncCache, AsyncCacheHandler, Cache, CacheHandler, createCache, TableN import { transformThread } from "./transformers/thread.ts"; import { transformWebhook } from "./transformers/webhook.ts"; import { transformAuditlogEntry } from "./transformers/auditlogEntry.ts"; +import { transformApplicationCommandPermission } from "./transformers/applicationCommandPermission.ts"; type CacheOptions = | { @@ -847,6 +848,7 @@ export interface Transformers { thread: typeof transformThread; webhook: typeof transformWebhook; auditlogEntry: typeof transformAuditlogEntry; + applicationCommandPermission: typeof transformApplicationCommandPermission } export function createTransformers(options: Partial) { @@ -873,6 +875,7 @@ export function createTransformers(options: Partial) { snowflake: options.snowflake || snowflakeToBigint, webhook: options.webhook || transformWebhook, auditlogEntry: options.auditlogEntry || transformAuditlogEntry, + applicationCommandPermission: transformApplicationCommandPermission }; } diff --git a/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts index a9682981c..90d830c1f 100644 --- a/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts @@ -1,5 +1,6 @@ import type { Bot } from "../../../bot.ts"; import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; +import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.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( @@ -7,10 +8,12 @@ export async function batchEditSlashCommandPermissions( guildId: bigint, options: { id: string; permissions: ApplicationCommandPermissions[] }[] ) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "put", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), options ); + + return result.map((res) => bot.transformers.applicationCommandPermission(bot, res)); } diff --git a/src/helpers/interactions/commands/edit_slash_command_permissions.ts b/src/helpers/interactions/commands/edit_slash_command_permissions.ts index 0ead8eaf2..8def52ec2 100644 --- a/src/helpers/interactions/commands/edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/edit_slash_command_permissions.ts @@ -1,5 +1,6 @@ import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; import type { Bot } from "../../../bot.ts"; +import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; /** Edits command permissions for a specific command for your application in a guild. */ export async function editSlashCommandPermissions( @@ -8,7 +9,7 @@ export async function editSlashCommandPermissions( commandId: bigint, options: ApplicationCommandPermissions[] ) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "put", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), @@ -16,4 +17,6 @@ export async function editSlashCommandPermissions( permissions: options, } ); + + return bot.transformers.applicationCommandPermission(bot, result); } diff --git a/src/transformers/applicationCommandPermission.ts b/src/transformers/applicationCommandPermission.ts new file mode 100644 index 000000000..82cc0e144 --- /dev/null +++ b/src/transformers/applicationCommandPermission.ts @@ -0,0 +1,38 @@ +import { Bot } from "../bot.ts"; +import { DiscordApplicationCommandPermissionTypes } from "../types/interactions/commands/application_command_permission_types.ts"; +import { GuildApplicationCommandPermissions } from "../types/interactions/commands/guild_application_command_permissions.ts"; +import { SnakeCasedPropertiesDeep } from "../types/util.ts"; + +export function transformApplicationCommandPermission( + bot: Bot, + payload: SnakeCasedPropertiesDeep +): DiscordenoApplicationCommandPermission { + return { + id: bot.transformers.snowflake(payload.id), + applicationId: bot.transformers.snowflake(payload.application_id), + guildId: bot.transformers.snowflake(payload.guild_id), + permissions: payload.permissions.map((perm) => ({ + id: bot.transformers.snowflake(perm.id), + type: perm.type, + permission: perm.permission, + })), + }; +} + +export interface DiscordenoApplicationCommandPermission { + /** The id of the command */ + id: bigint; + /** The id of the application to command belongs to */ + applicationId: bigint; + /** The id of the guild */ + guildId: bigint; + /** The permissions for the command in the guild */ + permissions: { + /** The id of the role or user */ + id: bigint; + /** Role or User */ + type: DiscordApplicationCommandPermissionTypes; + /** `true` to allow, `false`, to disallow */ + permission: boolean; + }[]; +}