From d7b666c739bb848ead5a3af09e37e64ed962014b Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 14 Dec 2022 21:18:41 +0000 Subject: [PATCH] feat: add role connections (#651) --- deno/payloads/v10/application.ts | 74 ++++++++++++++++++++++++++++++++ deno/payloads/v10/oauth2.ts | 4 ++ deno/payloads/v10/user.ts | 18 ++++++++ deno/payloads/v9/application.ts | 74 ++++++++++++++++++++++++++++++++ deno/payloads/v9/oauth2.ts | 4 ++ deno/payloads/v9/user.ts | 18 ++++++++ deno/rest/v10/application.ts | 16 +++++++ deno/rest/v10/mod.ts | 18 ++++++++ deno/rest/v10/user.ts | 37 +++++++++++++++- deno/rest/v9/application.ts | 16 +++++++ deno/rest/v9/mod.ts | 18 ++++++++ deno/rest/v9/user.ts | 37 +++++++++++++++- payloads/v10/application.ts | 74 ++++++++++++++++++++++++++++++++ payloads/v10/oauth2.ts | 4 ++ payloads/v10/user.ts | 18 ++++++++ payloads/v9/application.ts | 74 ++++++++++++++++++++++++++++++++ payloads/v9/oauth2.ts | 4 ++ payloads/v9/user.ts | 18 ++++++++ rest/v10/application.ts | 16 +++++++ rest/v10/index.ts | 18 ++++++++ rest/v10/user.ts | 37 +++++++++++++++- rest/v9/application.ts | 16 +++++++ rest/v9/index.ts | 18 ++++++++ rest/v9/user.ts | 37 +++++++++++++++- 24 files changed, 664 insertions(+), 4 deletions(-) create mode 100644 deno/rest/v10/application.ts create mode 100644 deno/rest/v9/application.ts create mode 100644 rest/v10/application.ts create mode 100644 rest/v9/application.ts diff --git a/deno/payloads/v10/application.ts b/deno/payloads/v10/application.ts index a1ead449..75e0dee8 100644 --- a/deno/payloads/v10/application.ts +++ b/deno/payloads/v10/application.ts @@ -6,6 +6,7 @@ import type { OAuth2Scopes } from './oauth2.ts'; import type { APITeam } from './teams.ts'; import type { APIUser } from './user.ts'; import type { Permissions, Snowflake } from '../../globals.ts'; +import type { LocalizationMap } from '../common.ts'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -105,6 +106,11 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * The application's role connection verification entry point, + * which when configured will render the app as a verification method in the guild role verification configuration + */ + role_connections_verification_url?: string; } export interface APIApplicationInstallParams { @@ -131,3 +137,71 @@ export enum ApplicationFlags { EmbeddedFirstParty = 1 << 20, ApplicationCommandBadge = 1 << 23, } + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-structure + */ +export interface APIApplicationRoleConnectionMetadata { + /** + * Type of metadata value + */ + type: ApplicationRoleConnectionMetadataType; + /** + * Dictionary key for the metadata field (must be `a-z`, `0-9`, or `_` characters; max 50 characters) + */ + key: string; + /** + * Name of the metadata field (max 100 characters) + */ + name: string; + /** + * Translations of the name + */ + name_localizations?: LocalizationMap; + /** + * Description of the metadata field (max 200 characters) + */ + description: string; + /** + * Translations of the description + */ + description_localizations?: LocalizationMap; +} + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type + */ +export enum ApplicationRoleConnectionMetadataType { + /** + * 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, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`) + */ + IntegerEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`) + */ + IntegerNotEqual, + /** + * The metadata value (`ISO8601 string`) is less than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeLessThanOrEqual, + /** + * The metadata value (`ISO8601 string`) is greater than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeGreaterThanOrEqual, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`; `1`) + */ + BooleanEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`; `1`) + */ + BooleanNotEqual, +} diff --git a/deno/payloads/v10/oauth2.ts b/deno/payloads/v10/oauth2.ts index dc745bab..b2016d51 100644 --- a/deno/payloads/v10/oauth2.ts +++ b/deno/payloads/v10/oauth2.ts @@ -61,6 +61,10 @@ export enum OAuth2Scopes { * (otherwise restricted to channels/guilds your app creates) */ MessagesRead = 'messages.read', + /** + * Allows your app to update a user's connection and metadata for the app + */ + RoleConnectionsWrite = 'role_connections.write', /** * For local rpc server access, this allows you to control a user's local Discord client - requires Discord approval */ diff --git a/deno/payloads/v10/user.ts b/deno/payloads/v10/user.ts index 75ace211..5c047066 100644 --- a/deno/payloads/v10/user.ts +++ b/deno/payloads/v10/user.ts @@ -255,3 +255,21 @@ export enum ConnectionVisibility { */ Everyone, } + +/** + * https://discord.com/developers/docs/resources/user#application-role-connection-object-application-role-connection-structure + */ +export interface APIApplicationRoleConnection { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name: string | null; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username: string | null; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata: Record; +} diff --git a/deno/payloads/v9/application.ts b/deno/payloads/v9/application.ts index a1ead449..75e0dee8 100644 --- a/deno/payloads/v9/application.ts +++ b/deno/payloads/v9/application.ts @@ -6,6 +6,7 @@ import type { OAuth2Scopes } from './oauth2.ts'; import type { APITeam } from './teams.ts'; import type { APIUser } from './user.ts'; import type { Permissions, Snowflake } from '../../globals.ts'; +import type { LocalizationMap } from '../common.ts'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -105,6 +106,11 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * The application's role connection verification entry point, + * which when configured will render the app as a verification method in the guild role verification configuration + */ + role_connections_verification_url?: string; } export interface APIApplicationInstallParams { @@ -131,3 +137,71 @@ export enum ApplicationFlags { EmbeddedFirstParty = 1 << 20, ApplicationCommandBadge = 1 << 23, } + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-structure + */ +export interface APIApplicationRoleConnectionMetadata { + /** + * Type of metadata value + */ + type: ApplicationRoleConnectionMetadataType; + /** + * Dictionary key for the metadata field (must be `a-z`, `0-9`, or `_` characters; max 50 characters) + */ + key: string; + /** + * Name of the metadata field (max 100 characters) + */ + name: string; + /** + * Translations of the name + */ + name_localizations?: LocalizationMap; + /** + * Description of the metadata field (max 200 characters) + */ + description: string; + /** + * Translations of the description + */ + description_localizations?: LocalizationMap; +} + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type + */ +export enum ApplicationRoleConnectionMetadataType { + /** + * 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, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`) + */ + IntegerEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`) + */ + IntegerNotEqual, + /** + * The metadata value (`ISO8601 string`) is less than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeLessThanOrEqual, + /** + * The metadata value (`ISO8601 string`) is greater than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeGreaterThanOrEqual, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`; `1`) + */ + BooleanEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`; `1`) + */ + BooleanNotEqual, +} diff --git a/deno/payloads/v9/oauth2.ts b/deno/payloads/v9/oauth2.ts index dc745bab..b2016d51 100644 --- a/deno/payloads/v9/oauth2.ts +++ b/deno/payloads/v9/oauth2.ts @@ -61,6 +61,10 @@ export enum OAuth2Scopes { * (otherwise restricted to channels/guilds your app creates) */ MessagesRead = 'messages.read', + /** + * Allows your app to update a user's connection and metadata for the app + */ + RoleConnectionsWrite = 'role_connections.write', /** * For local rpc server access, this allows you to control a user's local Discord client - requires Discord approval */ diff --git a/deno/payloads/v9/user.ts b/deno/payloads/v9/user.ts index 2e8c645b..37c93897 100644 --- a/deno/payloads/v9/user.ts +++ b/deno/payloads/v9/user.ts @@ -255,3 +255,21 @@ export enum ConnectionVisibility { */ Everyone, } + +/** + * https://discord.com/developers/docs/resources/user#application-role-connection-object-application-role-connection-structure + */ +export interface APIApplicationRoleConnection { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name: string | null; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username: string | null; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata: Record; +} diff --git a/deno/rest/v10/application.ts b/deno/rest/v10/application.ts new file mode 100644 index 00000000..4ccfea4b --- /dev/null +++ b/deno/rest/v10/application.ts @@ -0,0 +1,16 @@ +import type { APIApplicationRoleConnectionMetadata } from '../../payloads/v10/application.ts'; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records + */ +export type RESTGetAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataJSONBody = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; diff --git a/deno/rest/v10/mod.ts b/deno/rest/v10/mod.ts index 721a180b..ded0fbd1 100644 --- a/deno/rest/v10/mod.ts +++ b/deno/rest/v10/mod.ts @@ -1,6 +1,7 @@ import type { Snowflake } from '../../globals.ts'; export * from '../common.ts'; +export * from './application.ts'; export * from './auditLog.ts'; export * from './autoModeration.ts'; export * from './channel.ts'; @@ -21,6 +22,14 @@ export * from './webhook.ts'; export const APIVersion = '10'; export const Routes = { + /** + * Route for: + * - GET `/applications/{application.id}/role-connections/metadata` + * - PUT `/applications/{application.id}/role-connections/metadata` + */ + applicationRoleConnectionMetadata(applicationId: Snowflake) { + return `/applications/${applicationId}/role-connections/metadata` as const; + }, /** * Route for: * - GET `/guilds/{guild.id}/auto-moderation/rules` @@ -521,6 +530,15 @@ export const Routes = { return `/users/${userId}` as const; }, + /** + * Route for: + * - GET `/users/@me/applications/{application.id}/role-connection` + * - PUT `/users/@me/applications/{application.id}/role-connection` + */ + userApplicationRoleConnection(applicationId: Snowflake) { + return `/users/@me/applications/${applicationId}/role-connection` as const; + }, + /** * Route for: * - GET `/users/@me/guilds` diff --git a/deno/rest/v10/user.ts b/deno/rest/v10/user.ts index a9bd9ab3..e1cca2a5 100644 --- a/deno/rest/v10/user.ts +++ b/deno/rest/v10/user.ts @@ -1,5 +1,12 @@ import type { Permissions, Snowflake } from '../../globals.ts'; -import type { APIChannel, APIConnection, APIGuildMember, APIUser, GuildFeature } from '../../payloads/v10/mod.ts'; +import type { + APIChannel, + APIConnection, + APIGuildMember, + APIUser, + APIApplicationRoleConnection, + GuildFeature, +} from '../../payloads/v10/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals.ts'; /** @@ -94,3 +101,31 @@ export type RESTPostAPICurrentUserCreateDMChannelResult = APIChannel; * https://discord.com/developers/docs/resources/user#get-user-connections */ export type RESTGetAPICurrentUserConnectionsResult = APIConnection[]; + +/** + * https://discord.com/developers/docs/resources/user#get-user-application-role-connection + */ +export type RESTGetAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export interface RESTPutAPICurrentUserApplicationRoleConnectionJSONBody { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name?: string; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username?: string; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata?: Record; +} + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export type RESTPutAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; diff --git a/deno/rest/v9/application.ts b/deno/rest/v9/application.ts new file mode 100644 index 00000000..6c0521c0 --- /dev/null +++ b/deno/rest/v9/application.ts @@ -0,0 +1,16 @@ +import type { APIApplicationRoleConnectionMetadata } from '../../payloads/v9/application.ts'; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records + */ +export type RESTGetAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataJSONBody = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; diff --git a/deno/rest/v9/mod.ts b/deno/rest/v9/mod.ts index 4166c8b6..8e009812 100644 --- a/deno/rest/v9/mod.ts +++ b/deno/rest/v9/mod.ts @@ -1,6 +1,7 @@ import type { Snowflake } from '../../globals.ts'; export * from '../common.ts'; +export * from './application.ts'; export * from './auditLog.ts'; export * from './autoModeration.ts'; export * from './channel.ts'; @@ -21,6 +22,14 @@ export * from './webhook.ts'; export const APIVersion = '9'; export const Routes = { + /** + * Route for: + * - GET `/applications/{application.id}/role-connections/metadata` + * - PUT `/applications/{application.id}/role-connections/metadata` + */ + applicationRoleConnectionMetadata(applicationId: Snowflake) { + return `/applications/${applicationId}/role-connections/metadata` as const; + }, /** * Route for: * - GET `/guilds/{guild.id}/auto-moderation/rules` @@ -530,6 +539,15 @@ export const Routes = { return `/users/${userId}` as const; }, + /** + * Route for: + * - GET `/users/@me/applications/{application.id}/role-connection` + * - PUT `/users/@me/applications/{application.id}/role-connection` + */ + userApplicationRoleConnection(applicationId: Snowflake) { + return `/users/@me/applications/${applicationId}/role-connection` as const; + }, + /** * Route for: * - GET `/users/@me/guilds` diff --git a/deno/rest/v9/user.ts b/deno/rest/v9/user.ts index fcaade52..0120173a 100644 --- a/deno/rest/v9/user.ts +++ b/deno/rest/v9/user.ts @@ -1,5 +1,12 @@ import type { Permissions, Snowflake } from '../../globals.ts'; -import type { APIChannel, APIConnection, APIGuildMember, APIUser, GuildFeature } from '../../payloads/v9/mod.ts'; +import type { + APIChannel, + APIConnection, + APIGuildMember, + APIUser, + APIApplicationRoleConnection, + GuildFeature, +} from '../../payloads/v9/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals.ts'; /** @@ -94,3 +101,31 @@ export type RESTPostAPICurrentUserCreateDMChannelResult = APIChannel; * https://discord.com/developers/docs/resources/user#get-user-connections */ export type RESTGetAPICurrentUserConnectionsResult = APIConnection[]; + +/** + * https://discord.com/developers/docs/resources/user#get-user-application-role-connection + */ +export type RESTGetAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export interface RESTPutAPICurrentUserApplicationRoleConnectionJSONBody { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name?: string; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username?: string; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata?: Record; +} + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export type RESTPutAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; diff --git a/payloads/v10/application.ts b/payloads/v10/application.ts index 79f2c6eb..f62c6bcf 100644 --- a/payloads/v10/application.ts +++ b/payloads/v10/application.ts @@ -6,6 +6,7 @@ import type { OAuth2Scopes } from './oauth2'; import type { APITeam } from './teams'; import type { APIUser } from './user'; import type { Permissions, Snowflake } from '../../globals'; +import type { LocalizationMap } from '../common'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -105,6 +106,11 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * The application's role connection verification entry point, + * which when configured will render the app as a verification method in the guild role verification configuration + */ + role_connections_verification_url?: string; } export interface APIApplicationInstallParams { @@ -131,3 +137,71 @@ export enum ApplicationFlags { EmbeddedFirstParty = 1 << 20, ApplicationCommandBadge = 1 << 23, } + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-structure + */ +export interface APIApplicationRoleConnectionMetadata { + /** + * Type of metadata value + */ + type: ApplicationRoleConnectionMetadataType; + /** + * Dictionary key for the metadata field (must be `a-z`, `0-9`, or `_` characters; max 50 characters) + */ + key: string; + /** + * Name of the metadata field (max 100 characters) + */ + name: string; + /** + * Translations of the name + */ + name_localizations?: LocalizationMap; + /** + * Description of the metadata field (max 200 characters) + */ + description: string; + /** + * Translations of the description + */ + description_localizations?: LocalizationMap; +} + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type + */ +export enum ApplicationRoleConnectionMetadataType { + /** + * 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, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`) + */ + IntegerEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`) + */ + IntegerNotEqual, + /** + * The metadata value (`ISO8601 string`) is less than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeLessThanOrEqual, + /** + * The metadata value (`ISO8601 string`) is greater than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeGreaterThanOrEqual, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`; `1`) + */ + BooleanEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`; `1`) + */ + BooleanNotEqual, +} diff --git a/payloads/v10/oauth2.ts b/payloads/v10/oauth2.ts index dc745bab..b2016d51 100644 --- a/payloads/v10/oauth2.ts +++ b/payloads/v10/oauth2.ts @@ -61,6 +61,10 @@ export enum OAuth2Scopes { * (otherwise restricted to channels/guilds your app creates) */ MessagesRead = 'messages.read', + /** + * Allows your app to update a user's connection and metadata for the app + */ + RoleConnectionsWrite = 'role_connections.write', /** * For local rpc server access, this allows you to control a user's local Discord client - requires Discord approval */ diff --git a/payloads/v10/user.ts b/payloads/v10/user.ts index 536d0a99..9d190261 100644 --- a/payloads/v10/user.ts +++ b/payloads/v10/user.ts @@ -255,3 +255,21 @@ export enum ConnectionVisibility { */ Everyone, } + +/** + * https://discord.com/developers/docs/resources/user#application-role-connection-object-application-role-connection-structure + */ +export interface APIApplicationRoleConnection { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name: string | null; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username: string | null; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata: Record; +} diff --git a/payloads/v9/application.ts b/payloads/v9/application.ts index 79f2c6eb..f62c6bcf 100644 --- a/payloads/v9/application.ts +++ b/payloads/v9/application.ts @@ -6,6 +6,7 @@ import type { OAuth2Scopes } from './oauth2'; import type { APITeam } from './teams'; import type { APIUser } from './user'; import type { Permissions, Snowflake } from '../../globals'; +import type { LocalizationMap } from '../common'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -105,6 +106,11 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * The application's role connection verification entry point, + * which when configured will render the app as a verification method in the guild role verification configuration + */ + role_connections_verification_url?: string; } export interface APIApplicationInstallParams { @@ -131,3 +137,71 @@ export enum ApplicationFlags { EmbeddedFirstParty = 1 << 20, ApplicationCommandBadge = 1 << 23, } + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-structure + */ +export interface APIApplicationRoleConnectionMetadata { + /** + * Type of metadata value + */ + type: ApplicationRoleConnectionMetadataType; + /** + * Dictionary key for the metadata field (must be `a-z`, `0-9`, or `_` characters; max 50 characters) + */ + key: string; + /** + * Name of the metadata field (max 100 characters) + */ + name: string; + /** + * Translations of the name + */ + name_localizations?: LocalizationMap; + /** + * Description of the metadata field (max 200 characters) + */ + description: string; + /** + * Translations of the description + */ + description_localizations?: LocalizationMap; +} + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type + */ +export enum ApplicationRoleConnectionMetadataType { + /** + * 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, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`) + */ + IntegerEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`) + */ + IntegerNotEqual, + /** + * The metadata value (`ISO8601 string`) is less than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeLessThanOrEqual, + /** + * The metadata value (`ISO8601 string`) is greater than or equal to the guild's configured value (`integer`; days before current date) + */ + DatetimeGreaterThanOrEqual, + /** + * The metadata value (`integer`) is equal to the guild's configured value (`integer`; `1`) + */ + BooleanEqual, + /** + * The metadata value (`integer`) is not equal to the guild's configured value (`integer`; `1`) + */ + BooleanNotEqual, +} diff --git a/payloads/v9/oauth2.ts b/payloads/v9/oauth2.ts index dc745bab..b2016d51 100644 --- a/payloads/v9/oauth2.ts +++ b/payloads/v9/oauth2.ts @@ -61,6 +61,10 @@ export enum OAuth2Scopes { * (otherwise restricted to channels/guilds your app creates) */ MessagesRead = 'messages.read', + /** + * Allows your app to update a user's connection and metadata for the app + */ + RoleConnectionsWrite = 'role_connections.write', /** * For local rpc server access, this allows you to control a user's local Discord client - requires Discord approval */ diff --git a/payloads/v9/user.ts b/payloads/v9/user.ts index 4a7ec40f..2941e239 100644 --- a/payloads/v9/user.ts +++ b/payloads/v9/user.ts @@ -255,3 +255,21 @@ export enum ConnectionVisibility { */ Everyone, } + +/** + * https://discord.com/developers/docs/resources/user#application-role-connection-object-application-role-connection-structure + */ +export interface APIApplicationRoleConnection { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name: string | null; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username: string | null; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata: Record; +} diff --git a/rest/v10/application.ts b/rest/v10/application.ts new file mode 100644 index 00000000..775245e7 --- /dev/null +++ b/rest/v10/application.ts @@ -0,0 +1,16 @@ +import type { APIApplicationRoleConnectionMetadata } from '../../payloads/v10/application'; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records + */ +export type RESTGetAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataJSONBody = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; diff --git a/rest/v10/index.ts b/rest/v10/index.ts index c0f6fa8f..56cbfc53 100644 --- a/rest/v10/index.ts +++ b/rest/v10/index.ts @@ -1,6 +1,7 @@ import type { Snowflake } from '../../globals'; export * from '../common'; +export * from './application'; export * from './auditLog'; export * from './autoModeration'; export * from './channel'; @@ -21,6 +22,14 @@ export * from './webhook'; export const APIVersion = '10'; export const Routes = { + /** + * Route for: + * - GET `/applications/{application.id}/role-connections/metadata` + * - PUT `/applications/{application.id}/role-connections/metadata` + */ + applicationRoleConnectionMetadata(applicationId: Snowflake) { + return `/applications/${applicationId}/role-connections/metadata` as const; + }, /** * Route for: * - GET `/guilds/{guild.id}/auto-moderation/rules` @@ -521,6 +530,15 @@ export const Routes = { return `/users/${userId}` as const; }, + /** + * Route for: + * - GET `/users/@me/applications/{application.id}/role-connection` + * - PUT `/users/@me/applications/{application.id}/role-connection` + */ + userApplicationRoleConnection(applicationId: Snowflake) { + return `/users/@me/applications/${applicationId}/role-connection` as const; + }, + /** * Route for: * - GET `/users/@me/guilds` diff --git a/rest/v10/user.ts b/rest/v10/user.ts index 420d68ee..651ee7fe 100644 --- a/rest/v10/user.ts +++ b/rest/v10/user.ts @@ -1,5 +1,12 @@ import type { Permissions, Snowflake } from '../../globals'; -import type { APIChannel, APIConnection, APIGuildMember, APIUser, GuildFeature } from '../../payloads/v10/index'; +import type { + APIChannel, + APIConnection, + APIGuildMember, + APIUser, + APIApplicationRoleConnection, + GuildFeature, +} from '../../payloads/v10/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals'; /** @@ -94,3 +101,31 @@ export type RESTPostAPICurrentUserCreateDMChannelResult = APIChannel; * https://discord.com/developers/docs/resources/user#get-user-connections */ export type RESTGetAPICurrentUserConnectionsResult = APIConnection[]; + +/** + * https://discord.com/developers/docs/resources/user#get-user-application-role-connection + */ +export type RESTGetAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export interface RESTPutAPICurrentUserApplicationRoleConnectionJSONBody { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name?: string; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username?: string; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata?: Record; +} + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export type RESTPutAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; diff --git a/rest/v9/application.ts b/rest/v9/application.ts new file mode 100644 index 00000000..ca7ab3a7 --- /dev/null +++ b/rest/v9/application.ts @@ -0,0 +1,16 @@ +import type { APIApplicationRoleConnectionMetadata } from '../../payloads/v9/application'; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records + */ +export type RESTGetAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataJSONBody = APIApplicationRoleConnectionMetadata[]; + +/** + * https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records + */ +export type RESTPutAPIApplicationRoleConnectionMetadataResult = APIApplicationRoleConnectionMetadata[]; diff --git a/rest/v9/index.ts b/rest/v9/index.ts index e081f393..ad7f41c4 100644 --- a/rest/v9/index.ts +++ b/rest/v9/index.ts @@ -1,6 +1,7 @@ import type { Snowflake } from '../../globals'; export * from '../common'; +export * from './application'; export * from './auditLog'; export * from './autoModeration'; export * from './channel'; @@ -21,6 +22,14 @@ export * from './webhook'; export const APIVersion = '9'; export const Routes = { + /** + * Route for: + * - GET `/applications/{application.id}/role-connections/metadata` + * - PUT `/applications/{application.id}/role-connections/metadata` + */ + applicationRoleConnectionMetadata(applicationId: Snowflake) { + return `/applications/${applicationId}/role-connections/metadata` as const; + }, /** * Route for: * - GET `/guilds/{guild.id}/auto-moderation/rules` @@ -530,6 +539,15 @@ export const Routes = { return `/users/${userId}` as const; }, + /** + * Route for: + * - GET `/users/@me/applications/{application.id}/role-connection` + * - PUT `/users/@me/applications/{application.id}/role-connection` + */ + userApplicationRoleConnection(applicationId: Snowflake) { + return `/users/@me/applications/${applicationId}/role-connection` as const; + }, + /** * Route for: * - GET `/users/@me/guilds` diff --git a/rest/v9/user.ts b/rest/v9/user.ts index b93c184a..e04be76d 100644 --- a/rest/v9/user.ts +++ b/rest/v9/user.ts @@ -1,5 +1,12 @@ import type { Permissions, Snowflake } from '../../globals'; -import type { APIChannel, APIConnection, APIGuildMember, APIUser, GuildFeature } from '../../payloads/v9/index'; +import type { + APIChannel, + APIConnection, + APIGuildMember, + APIUser, + APIApplicationRoleConnection, + GuildFeature, +} from '../../payloads/v9/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface } from '../../utils/internals'; /** @@ -94,3 +101,31 @@ export type RESTPostAPICurrentUserCreateDMChannelResult = APIChannel; * https://discord.com/developers/docs/resources/user#get-user-connections */ export type RESTGetAPICurrentUserConnectionsResult = APIConnection[]; + +/** + * https://discord.com/developers/docs/resources/user#get-user-application-role-connection + */ +export type RESTGetAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection; + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export interface RESTPutAPICurrentUserApplicationRoleConnectionJSONBody { + /** + * The vanity name of the platform a bot has connected (max 50 characters) + */ + platform_name?: string; + /** + * The username on the platform a bot has connected (max 100 characters) + */ + platform_username?: string; + /** + * Object mapping application role connection metadata keys to their `string`-ified value (max 100 characters) for the user on the platform a bot has connected + */ + metadata?: Record; +} + +/** + * https://discord.com/developers/docs/resources/user#update-user-application-role-connection + */ +export type RESTPutAPICurrentUserApplicationRoleConnectionResult = APIApplicationRoleConnection;