feat: Support new application properties and patch endpoint (#9709)

* feat: support new application endpoints

* chore: edit comment

* fix(ClientApplication): handle flags properly

* types: `readonly`

* chore: update route

* feat: add to core

* refactor(ClientApplication): add to user manager

* chore: remove comments

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2023-10-10 15:25:26 +02:00
committed by GitHub
parent 44a3cbf39e
commit 1fe7247528
4 changed files with 122 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ const Team = require('./Team');
const Application = require('./interfaces/Application');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const ApplicationFlagsBitField = require('../util/ApplicationFlagsBitField');
const DataResolver = require('../util/DataResolver');
const PermissionsBitField = require('../util/PermissionsBitField');
/**
@@ -119,6 +120,16 @@ class ClientApplication extends Application {
this.botRequireCodeGrant ??= null;
}
if ('bot' in data) {
/**
* The bot associated with this application.
* @type {?User}
*/
this.bot = this.client.users._add(data.bot);
} else {
this.bot ??= null;
}
if ('bot_public' in data) {
/**
* If this application's bot is public
@@ -129,6 +140,16 @@ class ClientApplication extends Application {
this.botPublic ??= null;
}
if ('interactions_endpoint_url' in data) {
/**
* This application's interaction endpoint URL.
* @type {?string}
*/
this.interactionsEndpointURL = data.interactions_endpoint_url;
} else {
this.interactionsEndpointURL ??= null;
}
if ('role_connections_verification_url' in data) {
/**
* This application's role connection verification entry point URL
@@ -168,6 +189,55 @@ class ClientApplication extends Application {
return !this.name;
}
/**
* Options used for editing an application.
* @typedef {Object} ClientApplicationEditOptions
* @property {string} [customInstallURL] The application's custom installation URL
* @property {string} [description] The application's description
* @property {string} [roleConnectionsVerificationURL] The application's role connection verification URL
* @property {ClientApplicationInstallParams} [installParams]
* Settings for the application's default in-app authorization
* @property {ApplicationFlagsResolvable} [flags] The flags for the application
* @property {?(BufferResolvable|Base64Resolvable)} [icon] The application's icon
* @property {?(BufferResolvable|Base64Resolvable)} [coverImage] The application's cover image
* @property {string} [interactionsEndpointURL] The application's interaction endpoint URL
* @property {string[]} [tags] The application's tags
*/
/**
* Edits this application.
* @param {ClientApplicationEditOptions} [options] The options for editing this application
* @returns {Promise<ClientApplication>}
*/
async edit({
customInstallURL,
description,
roleConnectionsVerificationURL,
installParams,
flags,
icon,
coverImage,
interactionsEndpointURL,
tags,
} = {}) {
const data = await this.client.rest.patch(Routes.currentApplication(), {
body: {
custom_install_url: customInstallURL,
description,
role_connections_verification_url: roleConnectionsVerificationURL,
install_params: installParams,
flags: flags === undefined ? undefined : ApplicationFlagsBitField.resolve(flags),
icon: icon && (await DataResolver.resolveImage(icon)),
cover_image: coverImage && (await DataResolver.resolveImage(coverImage)),
interactions_endpoint_url: interactionsEndpointURL,
tags,
},
});
this._patch(data);
return this;
}
/**
* Obtains this application from Discord.
* @returns {Promise<ClientApplication>}

View File

@@ -23,4 +23,19 @@ class ApplicationFlagsBitField extends BitField {
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/
/**
* Bitfield of the packed bits
* @type {number}
* @name ApplicationFlagsBitField#bitfield
*/
/**
* Data that can be resolved to give an application flag bit field. This can be:
* * A string (see {@link ApplicationFlagsBitField.Flags})
* * An application flag
* * An instance of ApplicationFlagsBitField
* * An Array of ApplicationFlagsResolvable
* @typedef {string|number|ApplicationFlagsBitField|ApplicationFlagsResolvable[]} ApplicationFlagsResolvable
*/
module.exports = ApplicationFlagsBitField;