From e387f2cae2a175038b926f2865abc6aac9b5445e Mon Sep 17 00:00:00 2001 From: Fleny Date: Fri, 7 Feb 2025 16:42:46 +0100 Subject: [PATCH] feat(types,rest,bot): Add `ApplicationRoleConnectionMetadata` types (#4125) * add applicationRoleConnectionMetadata types * Update packages/rest/src/manager.ts Co-authored-by: LTS (Link) * Update packages/rest/src/manager.ts Co-authored-by: LTS (Link) --------- Co-authored-by: LTS (Link) --- packages/bot/src/helpers.ts | 12 +++++ packages/rest/src/manager.ts | 11 ++++ packages/rest/src/routes.ts | 4 ++ packages/rest/src/types.ts | 22 ++++++++ packages/rest/src/typings/routes.ts | 2 + .../applicationRoleConnectionMetadata.ts | 54 +++++++++++++++++++ packages/types/src/index.ts | 1 + 7 files changed, 106 insertions(+) create mode 100644 packages/types/src/discord/applicationRoleConnectionMetadata.ts diff --git a/packages/bot/src/helpers.ts b/packages/bot/src/helpers.ts index 6870f864e..0cc2e0d52 100644 --- a/packages/bot/src/helpers.ts +++ b/packages/bot/src/helpers.ts @@ -32,6 +32,7 @@ import type { DiscordActivityInstance, DiscordApplicationCommandPermissions, DiscordApplicationRoleConnection, + DiscordApplicationRoleConnectionMetadata, DiscordArchivedThreads, DiscordAuditLog, DiscordBan, @@ -600,6 +601,12 @@ export function createBotHelpers { return await bot.rest.getApplicationActivityInstance(applicationId, instanceId) }, + listApplicationRoleConnectionsMetadataRecords: async (applicationId) => { + return await bot.rest.listApplicationRoleConnectionsMetadataRecords(applicationId) + }, + updateApplicationRoleConnectionsMetadataRecords: async (applicationId, options) => { + return await bot.rest.updateApplicationRoleConnectionsMetadataRecords(applicationId, options) + }, // All useless void return functions here addReaction: async (channelId, messageId, reaction) => { return await bot.rest.addReaction(channelId, messageId, reaction) @@ -1063,6 +1070,11 @@ export type BotHelpers Promise[]> bulkBanMembers: (guildId: BigString, options: CreateGuildBulkBan, reason?: string) => Promise<{ bannedUsers: bigint[]; failedUsers: bigint[] }> getApplicationActivityInstance: (applicationId: BigString, instanceId: string) => Promise> + listApplicationRoleConnectionsMetadataRecords: (applicationId: BigString) => Promise[]> + updateApplicationRoleConnectionsMetadataRecords: ( + applicationId: BigString, + options: Camelize[], + ) => Promise[]> // functions return Void so dont need any special handling addReaction: (channelId: BigString, messageId: BigString, reaction: string) => Promise addReactions: (channelId: BigString, messageId: BigString, reactions: string[], ordered?: boolean) => Promise diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 90a7dc8a3..290e58bf9 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -7,6 +7,7 @@ import { type DiscordApplication, type DiscordApplicationCommand, type DiscordApplicationRoleConnection, + type DiscordApplicationRoleConnectionMetadata, type DiscordAuditLog, type DiscordAutoModerationRule, type DiscordBan, @@ -1699,6 +1700,16 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }) }, + async listApplicationRoleConnectionsMetadataRecords(applicationId) { + return await rest.get(rest.routes.applicationRoleConnectionMetadata(applicationId)) + }, + + async updateApplicationRoleConnectionsMetadataRecords(applicationId, options) { + return await rest.put(rest.routes.applicationRoleConnectionMetadata(applicationId), { + body: options, + }) + }, + preferSnakeCase(enabled: boolean) { const camelizer = enabled ? (x: any) => x : camelize diff --git a/packages/rest/src/routes.ts b/packages/rest/src/routes.ts index 8242fc56e..828def86e 100644 --- a/packages/rest/src/routes.ts +++ b/packages/rest/src/routes.ts @@ -638,6 +638,10 @@ export function createRoutes(): RestRoutes { return `/applications/${applicationId}/emojis` }, + applicationRoleConnectionMetadata(applicationId) { + return `/applications/${applicationId}/role-connections/metadata` + }, + // User endpoints user(userId) { return `/users/${userId}` diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index e475fb20d..3992ee9ea 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -35,6 +35,7 @@ import type { DiscordApplicationCommand, DiscordApplicationCommandPermissions, DiscordApplicationRoleConnection, + DiscordApplicationRoleConnectionMetadata, DiscordArchivedThreads, DiscordAuditLog, DiscordAutoModerationRule, @@ -3137,6 +3138,27 @@ export interface RestManager { * For other sounds, requires the `MANAGE_GUILD_EXPRESSIONS` permission. */ deleteGuildSoundboardSound: (guildId: BigString, soundId: BigString, reason?: string) => Promise + /** + * Returns a list of application role connection metadata objects for the given application. + * + * @param applicationId - The application to get the role connections from + * @returns A list of application role connection metadata objects + */ + listApplicationRoleConnectionsMetadataRecords: (applicationId: BigString) => Promise[]> + /** + * Updates and returns a list of application role connection metadata objects for the given application. + * + * @param applicationId - The application to get the role connections from + * @param options - The options to update the role connections + * @returns A list of application role connection metadata objects + * + * @remarks + * An application can have a maximum of 5 metadata records. + */ + updateApplicationRoleConnectionsMetadataRecords: ( + applicationId: BigString, + options: Camelize[], + ) => Promise[]> } export type RequestMethods = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'PUT' diff --git a/packages/rest/src/typings/routes.ts b/packages/rest/src/typings/routes.ts index 303359946..5853a8932 100644 --- a/packages/rest/src/typings/routes.ts +++ b/packages/rest/src/typings/routes.ts @@ -295,6 +295,8 @@ export interface RestRoutes { } /** Route to list / create an application emoji */ applicationEmojis: (applicationId: BigString) => string + /** Route to list / update application role connection metadata records */ + applicationRoleConnectionMetadata: (applicationId: BigString) => string /** Route to get / edit / delete an application emoji */ applicationEmoji: (applicationId: BigString, emojiId: BigString) => string /** Get information about the current OAuth2 user / bot user. If used with a OAuth2 token requires the `identify` OAuth2 scope */ diff --git a/packages/types/src/discord/applicationRoleConnectionMetadata.ts b/packages/types/src/discord/applicationRoleConnectionMetadata.ts new file mode 100644 index 000000000..62d2f3567 --- /dev/null +++ b/packages/types/src/discord/applicationRoleConnectionMetadata.ts @@ -0,0 +1,54 @@ +/** Types for: https://discord.com/developers/docs/resources/application-role-connection-metadata */ + +import type { Localization } from './reference.js' + +/** https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-structure */ +export interface DiscordApplicationRoleConnectionMetadata { + /** Type of metadata value */ + type: DiscordApplicationRoleConnectionMetadataType + /** + * Dictionary key for the metadata field + * + * @remarks + * Must be a-z, 0-9, or _ characters; 1-50 characters + */ + key: string + /** + * Name of the metadata field + * + * @remarks + * 1-100 characters + */ + name: string + /** Translations of the name */ + name_localizations?: Localization + /** + * Description of the metadata field + * + * @remarks + * 1-200 characters + */ + description: string + /** Translations of the description */ + description_localizations: Localization +} + +/** https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type */ +export enum DiscordApplicationRoleConnectionMetadataType { + /** The metadata value (integer) is less than or equal to the guild's configured value (integer) */ + IntegerLessThanOrEqual = 1, + /** The metadata value (integer) is greater than or equal to the guild's configured value (integer) */ + IntegerGreaterThanOrEqual = 2, + /** The metadata value (integer) is equal to the guild's configured value (integer) */ + IntegerEqual = 3, + /** The metadata value (integer) is not equal to the guild's configured value (integer) */ + IntegerNotEqual = 4, + /** The metadata value (ISO8601 string) is less than or equal to the guild's configured value (integer; days before current date) */ + DatetimeLessThanOrEqual = 5, + /** The metadata value (ISO8601 string) is greater than or equal to the guild's configured value (integer; days before current date) */ + DatetimeGreaterThanOrEqual = 6, + /** The metadata value (integer) is equal to the guild's configured value (integer; 1) */ + BooleanEqual = 7, + /** The metadata value (integer) is not equal to the guild's configured value (integer; 1) */ + BooleanNotEqual = 8, +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index b22db6f15..9c861c31e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,4 +1,5 @@ export * from './discord/application.js' +export * from './discord/applicationRoleConnectionMetadata.js' export * from './discord/auditLog.js' export * from './discord/autoModeration.js' export * from './discord/channel.js'