From 3d6fa248c07b2278504bbe8bafa17a3294971fd9 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Thu, 15 Dec 2022 21:32:00 -0500 Subject: [PATCH] feat(core): Add support for role connections (#8930) --- packages/core/package.json | 2 +- packages/core/src/api/roleConnections.ts | 40 +++++++++++++++++++++++ packages/core/src/api/user.ts | 41 ++++++++++++++++++++++++ packages/rest/package.json | 2 +- packages/ws/package.json | 2 +- yarn.lock | 13 ++++++-- 6 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 packages/core/src/api/roleConnections.ts diff --git a/packages/core/package.json b/packages/core/package.json index 54f8fe9f3cb2..c1e6705f45b4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -48,7 +48,7 @@ "@discordjs/rest": "workspace:^", "@discordjs/ws": "workspace:^", "@vladfrangu/async_event_emitter": "^2.1.2", - "discord-api-types": "^0.37.20" + "discord-api-types": "^0.37.23" }, "devDependencies": { "@favware/cliff-jumper": "^1.9.0", diff --git a/packages/core/src/api/roleConnections.ts b/packages/core/src/api/roleConnections.ts new file mode 100644 index 000000000000..e81981da43ce --- /dev/null +++ b/packages/core/src/api/roleConnections.ts @@ -0,0 +1,40 @@ +import type { REST } from '@discordjs/rest'; +import { + Routes, + type RESTGetAPIApplicationRoleConnectionMetadataResult, + type RESTPutAPIApplicationRoleConnectionMetadataResult, + type RESTPutAPIApplicationCommandPermissionsJSONBody, + type Snowflake, +} from 'discord-api-types/v10'; + +export class RoleConnectionsAPI { + public constructor(private readonly rest: REST) {} + + /** + * Gets the role connection metadata records for the application + * + * @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records} + * @param applicationId - The id of the application to get role connection metadata records for + */ + public async getMetadataRecords(applicationId: Snowflake) { + return this.rest.get( + Routes.applicationRoleConnectionMetadata(applicationId), + ) as Promise; + } + + /** + * Updates the role connection metadata records for the application + * + * @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records} + * @param applicationId - The id of the application to update role connection metadata records for + * @param options - The new role connection metadata records + */ + public async updateMetadataRecords( + applicationId: Snowflake, + options: RESTPutAPIApplicationCommandPermissionsJSONBody, + ) { + return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), { + body: options, + }) as Promise; + } +} diff --git a/packages/core/src/api/user.ts b/packages/core/src/api/user.ts index cb639cb04e88..26d83acf3613 100644 --- a/packages/core/src/api/user.ts +++ b/packages/core/src/api/user.ts @@ -1,6 +1,8 @@ import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, + type RESTGetAPICurrentUserApplicationRoleConnectionResult, + type RESTGetAPICurrentUserConnectionsResult, type RESTGetAPICurrentUserGuildsQuery, type RESTGetAPICurrentUserGuildsResult, type RESTGetAPICurrentUserResult, @@ -13,6 +15,8 @@ import { type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody, type RESTPatchAPIGuildVoiceStateCurrentMemberResult, type RESTPostAPICurrentUserCreateDMChannelResult, + type RESTPutAPICurrentUserApplicationRoleConnectionJSONBody, + type RESTPutAPICurrentUserApplicationRoleConnectionResult, type Snowflake, } from 'discord-api-types/v10'; @@ -119,4 +123,41 @@ export class UsersAPI { body: { recipient_id: userId }, }) as Promise; } + + /** + * Gets the current user's connections + * + * @see {@link https://discord.com/developers/docs/resources/user#get-user-connections} + */ + public async getConnections() { + return this.rest.get(Routes.userConnections()) as Promise; + } + + /** + * Gets the current user's active application role connection + * + * @see {@link https://discord.com/developers/docs/resources/user#get-user-application-role-connection} + * @param applicationId - The id of the application + */ + public async getApplicationRoleConnection(applicationId: Snowflake) { + return this.rest.get( + Routes.userApplicationRoleConnection(applicationId), + ) as Promise; + } + + /** + * Updates the current user's application role connection + * + * @see {@link https://discord.com/developers/docs/resources/user#update-user-application-role-connection} + * @param applicationId - The id of the application + * @param options - The options to use when updating the application role connection + */ + public async updateApplicationRoleConnection( + applicationId: Snowflake, + options: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody, + ) { + return this.rest.put(Routes.userApplicationRoleConnection(applicationId), { + body: options, + }) as Promise; + } } diff --git a/packages/rest/package.json b/packages/rest/package.json index 99322fed55e3..b598afa98594 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -56,7 +56,7 @@ "@discordjs/util": "workspace:^", "@sapphire/async-queue": "^1.5.0", "@sapphire/snowflake": "^3.2.2", - "discord-api-types": "^0.37.20", + "discord-api-types": "^0.37.23", "file-type": "^18.0.0", "tslib": "^2.4.1", "undici": "^5.13.0" diff --git a/packages/ws/package.json b/packages/ws/package.json index 5973bb2d09ad..fe506920abb5 100644 --- a/packages/ws/package.json +++ b/packages/ws/package.json @@ -58,7 +58,7 @@ "@sapphire/async-queue": "^1.5.0", "@types/ws": "^8.5.3", "@vladfrangu/async_event_emitter": "^2.1.2", - "discord-api-types": "^0.37.20", + "discord-api-types": "^0.37.23", "tslib": "^2.4.1", "ws": "^8.11.0" }, diff --git a/yarn.lock b/yarn.lock index 629e6d0237d9..0379c31b8912 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2102,7 +2102,7 @@ __metadata: "@vitest/coverage-c8": ^0.25.3 "@vladfrangu/async_event_emitter": ^2.1.2 cross-env: ^7.0.3 - discord-api-types: ^0.37.20 + discord-api-types: ^0.37.23 eslint: ^8.28.0 eslint-config-neon: ^0.1.40 eslint-formatter-pretty: ^4.1.0 @@ -2283,7 +2283,7 @@ __metadata: "@types/node": 16.18.4 "@vitest/coverage-c8": ^0.25.3 cross-env: ^7.0.3 - discord-api-types: ^0.37.20 + discord-api-types: ^0.37.23 esbuild-plugin-version-injector: ^1.0.2 eslint: ^8.28.0 eslint-config-neon: ^0.1.40 @@ -2478,7 +2478,7 @@ __metadata: "@vitest/coverage-c8": ^0.25.3 "@vladfrangu/async_event_emitter": ^2.1.2 cross-env: ^7.0.3 - discord-api-types: ^0.37.20 + discord-api-types: ^0.37.23 esbuild-plugin-version-injector: ^1.0.2 eslint: ^8.28.0 eslint-config-neon: ^0.1.40 @@ -8464,6 +8464,13 @@ __metadata: languageName: node linkType: hard +"discord-api-types@npm:^0.37.23": + version: 0.37.23 + resolution: "discord-api-types@npm:0.37.23" + checksum: 68c385366ccec523c35db4048f2c0d1fcd979fefb620ba57707dc648d0e647b817047a03682d9cac2e9e9a1642f2129ad343ac66a7a9b1e0d6bf53bc5eb11f37 + languageName: node + linkType: hard + "discord.js@workspace:packages/discord.js": version: 0.0.0-use.local resolution: "discord.js@workspace:packages/discord.js"