Skip to content

Commit

Permalink
feat(core): Add support for role connections (#8930)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Dec 16, 2022
1 parent 273ba45 commit 3d6fa24
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions 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<RESTGetAPIApplicationRoleConnectionMetadataResult>;
}

/**
* 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<RESTPutAPIApplicationRoleConnectionMetadataResult>;
}
}
41 changes: 41 additions & 0 deletions 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,
Expand All @@ -13,6 +15,8 @@ import {
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
type RESTPatchAPIGuildVoiceStateCurrentMemberResult,
type RESTPostAPICurrentUserCreateDMChannelResult,
type RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
type RESTPutAPICurrentUserApplicationRoleConnectionResult,
type Snowflake,
} from 'discord-api-types/v10';

Expand Down Expand Up @@ -119,4 +123,41 @@ export class UsersAPI {
body: { recipient_id: userId },
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
}

/**
* 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<RESTGetAPICurrentUserConnectionsResult>;
}

/**
* 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<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
}

/**
* 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<RESTPutAPICurrentUserApplicationRoleConnectionResult>;
}
}
2 changes: 1 addition & 1 deletion packages/rest/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/ws/package.json
Expand Up @@ -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"
},
Expand Down
13 changes: 10 additions & 3 deletions yarn.lock
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 3d6fa24

Please sign in to comment.