feat(core): Add support for role connections (#8930)

This commit is contained in:
Suneet Tipirneni
2022-12-15 21:32:00 -05:00
committed by GitHub
parent 273ba45e27
commit 3d6fa248c0
6 changed files with 94 additions and 6 deletions

View File

@@ -48,7 +48,7 @@
"@discordjs/rest": "workspace:^", "@discordjs/rest": "workspace:^",
"@discordjs/ws": "workspace:^", "@discordjs/ws": "workspace:^",
"@vladfrangu/async_event_emitter": "^2.1.2", "@vladfrangu/async_event_emitter": "^2.1.2",
"discord-api-types": "^0.37.20" "discord-api-types": "^0.37.23"
}, },
"devDependencies": { "devDependencies": {
"@favware/cliff-jumper": "^1.9.0", "@favware/cliff-jumper": "^1.9.0",

View File

@@ -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>;
}
}

View File

@@ -1,6 +1,8 @@
import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTGetAPICurrentUserApplicationRoleConnectionResult,
type RESTGetAPICurrentUserConnectionsResult,
type RESTGetAPICurrentUserGuildsQuery, type RESTGetAPICurrentUserGuildsQuery,
type RESTGetAPICurrentUserGuildsResult, type RESTGetAPICurrentUserGuildsResult,
type RESTGetAPICurrentUserResult, type RESTGetAPICurrentUserResult,
@@ -13,6 +15,8 @@ import {
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody, type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
type RESTPatchAPIGuildVoiceStateCurrentMemberResult, type RESTPatchAPIGuildVoiceStateCurrentMemberResult,
type RESTPostAPICurrentUserCreateDMChannelResult, type RESTPostAPICurrentUserCreateDMChannelResult,
type RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
type RESTPutAPICurrentUserApplicationRoleConnectionResult,
type Snowflake, type Snowflake,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
@@ -119,4 +123,41 @@ export class UsersAPI {
body: { recipient_id: userId }, body: { recipient_id: userId },
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>; }) 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>;
}
} }

View File

@@ -56,7 +56,7 @@
"@discordjs/util": "workspace:^", "@discordjs/util": "workspace:^",
"@sapphire/async-queue": "^1.5.0", "@sapphire/async-queue": "^1.5.0",
"@sapphire/snowflake": "^3.2.2", "@sapphire/snowflake": "^3.2.2",
"discord-api-types": "^0.37.20", "discord-api-types": "^0.37.23",
"file-type": "^18.0.0", "file-type": "^18.0.0",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"undici": "^5.13.0" "undici": "^5.13.0"

View File

@@ -58,7 +58,7 @@
"@sapphire/async-queue": "^1.5.0", "@sapphire/async-queue": "^1.5.0",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
"@vladfrangu/async_event_emitter": "^2.1.2", "@vladfrangu/async_event_emitter": "^2.1.2",
"discord-api-types": "^0.37.20", "discord-api-types": "^0.37.23",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"ws": "^8.11.0" "ws": "^8.11.0"
}, },

View File

@@ -2102,7 +2102,7 @@ __metadata:
"@vitest/coverage-c8": ^0.25.3 "@vitest/coverage-c8": ^0.25.3
"@vladfrangu/async_event_emitter": ^2.1.2 "@vladfrangu/async_event_emitter": ^2.1.2
cross-env: ^7.0.3 cross-env: ^7.0.3
discord-api-types: ^0.37.20 discord-api-types: ^0.37.23
eslint: ^8.28.0 eslint: ^8.28.0
eslint-config-neon: ^0.1.40 eslint-config-neon: ^0.1.40
eslint-formatter-pretty: ^4.1.0 eslint-formatter-pretty: ^4.1.0
@@ -2283,7 +2283,7 @@ __metadata:
"@types/node": 16.18.4 "@types/node": 16.18.4
"@vitest/coverage-c8": ^0.25.3 "@vitest/coverage-c8": ^0.25.3
cross-env: ^7.0.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 esbuild-plugin-version-injector: ^1.0.2
eslint: ^8.28.0 eslint: ^8.28.0
eslint-config-neon: ^0.1.40 eslint-config-neon: ^0.1.40
@@ -2478,7 +2478,7 @@ __metadata:
"@vitest/coverage-c8": ^0.25.3 "@vitest/coverage-c8": ^0.25.3
"@vladfrangu/async_event_emitter": ^2.1.2 "@vladfrangu/async_event_emitter": ^2.1.2
cross-env: ^7.0.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 esbuild-plugin-version-injector: ^1.0.2
eslint: ^8.28.0 eslint: ^8.28.0
eslint-config-neon: ^0.1.40 eslint-config-neon: ^0.1.40
@@ -8464,6 +8464,13 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "discord.js@workspace:packages/discord.js":
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "discord.js@workspace:packages/discord.js" resolution: "discord.js@workspace:packages/discord.js"