Skip to content

Commit 3d6fa24

Browse files
feat(core): Add support for role connections (#8930)
1 parent 273ba45 commit 3d6fa24

File tree

6 files changed

+94
-6
lines changed

6 files changed

+94
-6
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@discordjs/rest": "workspace:^",
4949
"@discordjs/ws": "workspace:^",
5050
"@vladfrangu/async_event_emitter": "^2.1.2",
51-
"discord-api-types": "^0.37.20"
51+
"discord-api-types": "^0.37.23"
5252
},
5353
"devDependencies": {
5454
"@favware/cliff-jumper": "^1.9.0",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { REST } from '@discordjs/rest';
2+
import {
3+
Routes,
4+
type RESTGetAPIApplicationRoleConnectionMetadataResult,
5+
type RESTPutAPIApplicationRoleConnectionMetadataResult,
6+
type RESTPutAPIApplicationCommandPermissionsJSONBody,
7+
type Snowflake,
8+
} from 'discord-api-types/v10';
9+
10+
export class RoleConnectionsAPI {
11+
public constructor(private readonly rest: REST) {}
12+
13+
/**
14+
* Gets the role connection metadata records for the application
15+
*
16+
* @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records}
17+
* @param applicationId - The id of the application to get role connection metadata records for
18+
*/
19+
public async getMetadataRecords(applicationId: Snowflake) {
20+
return this.rest.get(
21+
Routes.applicationRoleConnectionMetadata(applicationId),
22+
) as Promise<RESTGetAPIApplicationRoleConnectionMetadataResult>;
23+
}
24+
25+
/**
26+
* Updates the role connection metadata records for the application
27+
*
28+
* @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records}
29+
* @param applicationId - The id of the application to update role connection metadata records for
30+
* @param options - The new role connection metadata records
31+
*/
32+
public async updateMetadataRecords(
33+
applicationId: Snowflake,
34+
options: RESTPutAPIApplicationCommandPermissionsJSONBody,
35+
) {
36+
return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), {
37+
body: options,
38+
}) as Promise<RESTPutAPIApplicationRoleConnectionMetadataResult>;
39+
}
40+
}

packages/core/src/api/user.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { makeURLSearchParams, type REST } from '@discordjs/rest';
22
import {
33
Routes,
4+
type RESTGetAPICurrentUserApplicationRoleConnectionResult,
5+
type RESTGetAPICurrentUserConnectionsResult,
46
type RESTGetAPICurrentUserGuildsQuery,
57
type RESTGetAPICurrentUserGuildsResult,
68
type RESTGetAPICurrentUserResult,
@@ -13,6 +15,8 @@ import {
1315
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
1416
type RESTPatchAPIGuildVoiceStateCurrentMemberResult,
1517
type RESTPostAPICurrentUserCreateDMChannelResult,
18+
type RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
19+
type RESTPutAPICurrentUserApplicationRoleConnectionResult,
1620
type Snowflake,
1721
} from 'discord-api-types/v10';
1822

@@ -119,4 +123,41 @@ export class UsersAPI {
119123
body: { recipient_id: userId },
120124
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
121125
}
126+
127+
/**
128+
* Gets the current user's connections
129+
*
130+
* @see {@link https://discord.com/developers/docs/resources/user#get-user-connections}
131+
*/
132+
public async getConnections() {
133+
return this.rest.get(Routes.userConnections()) as Promise<RESTGetAPICurrentUserConnectionsResult>;
134+
}
135+
136+
/**
137+
* Gets the current user's active application role connection
138+
*
139+
* @see {@link https://discord.com/developers/docs/resources/user#get-user-application-role-connection}
140+
* @param applicationId - The id of the application
141+
*/
142+
public async getApplicationRoleConnection(applicationId: Snowflake) {
143+
return this.rest.get(
144+
Routes.userApplicationRoleConnection(applicationId),
145+
) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
146+
}
147+
148+
/**
149+
* Updates the current user's application role connection
150+
*
151+
* @see {@link https://discord.com/developers/docs/resources/user#update-user-application-role-connection}
152+
* @param applicationId - The id of the application
153+
* @param options - The options to use when updating the application role connection
154+
*/
155+
public async updateApplicationRoleConnection(
156+
applicationId: Snowflake,
157+
options: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
158+
) {
159+
return this.rest.put(Routes.userApplicationRoleConnection(applicationId), {
160+
body: options,
161+
}) as Promise<RESTPutAPICurrentUserApplicationRoleConnectionResult>;
162+
}
122163
}

packages/rest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@discordjs/util": "workspace:^",
5757
"@sapphire/async-queue": "^1.5.0",
5858
"@sapphire/snowflake": "^3.2.2",
59-
"discord-api-types": "^0.37.20",
59+
"discord-api-types": "^0.37.23",
6060
"file-type": "^18.0.0",
6161
"tslib": "^2.4.1",
6262
"undici": "^5.13.0"

packages/ws/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@sapphire/async-queue": "^1.5.0",
5959
"@types/ws": "^8.5.3",
6060
"@vladfrangu/async_event_emitter": "^2.1.2",
61-
"discord-api-types": "^0.37.20",
61+
"discord-api-types": "^0.37.23",
6262
"tslib": "^2.4.1",
6363
"ws": "^8.11.0"
6464
},

yarn.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ __metadata:
21022102
"@vitest/coverage-c8": ^0.25.3
21032103
"@vladfrangu/async_event_emitter": ^2.1.2
21042104
cross-env: ^7.0.3
2105-
discord-api-types: ^0.37.20
2105+
discord-api-types: ^0.37.23
21062106
eslint: ^8.28.0
21072107
eslint-config-neon: ^0.1.40
21082108
eslint-formatter-pretty: ^4.1.0
@@ -2283,7 +2283,7 @@ __metadata:
22832283
"@types/node": 16.18.4
22842284
"@vitest/coverage-c8": ^0.25.3
22852285
cross-env: ^7.0.3
2286-
discord-api-types: ^0.37.20
2286+
discord-api-types: ^0.37.23
22872287
esbuild-plugin-version-injector: ^1.0.2
22882288
eslint: ^8.28.0
22892289
eslint-config-neon: ^0.1.40
@@ -2478,7 +2478,7 @@ __metadata:
24782478
"@vitest/coverage-c8": ^0.25.3
24792479
"@vladfrangu/async_event_emitter": ^2.1.2
24802480
cross-env: ^7.0.3
2481-
discord-api-types: ^0.37.20
2481+
discord-api-types: ^0.37.23
24822482
esbuild-plugin-version-injector: ^1.0.2
24832483
eslint: ^8.28.0
24842484
eslint-config-neon: ^0.1.40
@@ -8464,6 +8464,13 @@ __metadata:
84648464
languageName: node
84658465
linkType: hard
84668466

8467+
"discord-api-types@npm:^0.37.23":
8468+
version: 0.37.23
8469+
resolution: "discord-api-types@npm:0.37.23"
8470+
checksum: 68c385366ccec523c35db4048f2c0d1fcd979fefb620ba57707dc648d0e647b817047a03682d9cac2e9e9a1642f2129ad343ac66a7a9b1e0d6bf53bc5eb11f37
8471+
languageName: node
8472+
linkType: hard
8473+
84678474
"discord.js@workspace:packages/discord.js":
84688475
version: 0.0.0-use.local
84698476
resolution: "discord.js@workspace:packages/discord.js"

0 commit comments

Comments
 (0)