diff --git a/src/bot.ts b/src/bot.ts index 67bd81265..1f23efdde 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 = | { @@ -848,6 +849,7 @@ export interface Transformers { thread: typeof transformThread; webhook: typeof transformWebhook; auditlogEntry: typeof transformAuditlogEntry; + applicationCommandPermission: typeof transformApplicationCommandPermission } export function createTransformers(options: Partial) { @@ -874,6 +876,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/application.ts b/src/transformers/application.ts index c58cd7c1c..1336b8f67 100644 --- a/src/transformers/application.ts +++ b/src/transformers/application.ts @@ -66,5 +66,5 @@ export interface DiscordenoApplication { /** If this application is a game sold on Discord, this field will be the hash of the image on store embeds */ coverImage?: string; /** The application's public flags */ - flags: DiscordApplicationFlags; + flags?: DiscordApplicationFlags; } 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; + }[]; +} diff --git a/src/types/applications/application.ts b/src/types/applications/application.ts index 904901286..d0423450e 100644 --- a/src/types/applications/application.ts +++ b/src/types/applications/application.ts @@ -39,5 +39,5 @@ export interface Application { /** If this application is a game sold on Discord, this field will be the hash of the image on store embeds */ coverImage?: string; /** The application's public flags */ - flags: DiscordApplicationFlags; + flags?: DiscordApplicationFlags; } diff --git a/src/types/codes/json_error_codes.ts b/src/types/codes/json_error_codes.ts index 4682476f9..e031f4293 100644 --- a/src/types/codes/json_error_codes.ts +++ b/src/types/codes/json_error_codes.ts @@ -33,7 +33,8 @@ export enum DiscordJsonErrorCodes { UnknownInteraction = 10062, UnknownApplicationCommand = 10063, UnknownApplicationCommandPermissions = 10066, - UnknownGuildMemberVerificationForm = 10068, + UnknownStageInstance, + UnknownGuildMemberVerificationForm, BotsCannotUseThisEndpoint = 20001, OnlyBotsCanUseThisEndpoint, ExplicitContentCannotBeSentToTheDesiredRecipient = 20009, @@ -42,7 +43,7 @@ export enum DiscordJsonErrorCodes { OnlyTheOwnerOfThisAccountCanPerformThisAction = 20018, ThisMessageCannotBeEditedDueToAnnouncementRateLimits = 20022, TheChannelYouAreWritingHasHitTheWriteRateLimit = 20028, - YourStageTopicContainsWordsThatAreNotAllowedForPublicStages = 20031, + YourStageTopicOrServerNameOrServerDescriptionOrChannelNamesContainsWordsThatAreNotAllowedForPublicStages = 20031, GuildPremiumSubscriptionLevelTooLow = 20035, MaximumNumberOfGuildsReached = 30001, MaximumNumberOfFriendsReached, @@ -110,6 +111,7 @@ export enum DiscordJsonErrorCodes { NoUsersWithDiscordTagExist = 80004, ReqctionWasBlocked = 90001, ApiResourceIsCurrentlyOverloadedTryAgainALittleLater = 130000, + TheStageIsAlreadyOpen = 150006, AThreadHasAlreadyBeenCreatedForThisMessage = 160004, ThreadIsLocked = 160005, MaximumNumberOfActiveThreadsReached = 160006, diff --git a/src/types/messages/message_sticker.ts b/src/types/messages/message_sticker.ts index 92d477daf..4c23dd4d8 100644 --- a/src/types/messages/message_sticker.ts +++ b/src/types/messages/message_sticker.ts @@ -11,14 +11,8 @@ export interface MessageSticker { name: string; /** Description of the sticker */ description: string; - /** For guild stickers, a unicode emoji representing the sticker's expression. For Nitro stickers, a comma-separated list of related expressions */ + /** a unicode emoji representing the sticker's expression */ tags: string; - /** - * Sticker asset hash - * Note: The URL for fetching sticker assets is currently private. - * @deprecated the value of the asset field will an empty string. - */ - asset: string; /** Type of sticker format */ formatType: DiscordMessageStickerFormatTypes; /** Whether or not the sticker is available */