mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
misc: update ClientApplication for the current API (#2767)
* misc: Update ClientApplication for the current API
* cleanup: ClientApplication#fetchAssets, removed createAsset
* Major cleanup time
* Merge to kyra's branch
* docs: Updated typings
* fix: re-add ClientApplication#{cover,coverImage()}
* typings(ClientApplication): move coverImage declaration up
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const { ClientApplicationAssetTypes, Endpoints } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Base = require('./Base');
|
||||
|
||||
const AssetTypes = Object.keys(ClientApplicationAssetTypes);
|
||||
|
||||
/**
|
||||
* Represents a Client OAuth2 Application.
|
||||
* @extends {Base}
|
||||
@@ -39,22 +40,16 @@ class ClientApplication extends Base {
|
||||
this.icon = data.icon;
|
||||
|
||||
/**
|
||||
* The app's cover image hash
|
||||
* The app's cover image
|
||||
* @type {?string}
|
||||
*/
|
||||
this.cover = data.cover_image;
|
||||
this.cover = data.cover_image || null;
|
||||
|
||||
/**
|
||||
* The app's RPC origins
|
||||
* The app's RPC origins, if enabled
|
||||
* @type {?string[]}
|
||||
*/
|
||||
this.rpcOrigins = data.rpc_origins;
|
||||
|
||||
/**
|
||||
* The app's redirect URIs
|
||||
* @type {string[]}
|
||||
*/
|
||||
this.redirectURIs = data.redirect_uris;
|
||||
this.rpcOrigins = data.rpc_origins || [];
|
||||
|
||||
/**
|
||||
* If this app's bot requires a code grant when using the OAuth2 flow
|
||||
@@ -69,36 +64,10 @@ class ClientApplication extends Base {
|
||||
this.botPublic = data.bot_public;
|
||||
|
||||
/**
|
||||
* If this app can use rpc
|
||||
* @type {boolean}
|
||||
* The owner of this OAuth application
|
||||
* @type {User}
|
||||
*/
|
||||
this.rpcApplicationState = data.rpc_application_state;
|
||||
|
||||
/**
|
||||
* Object containing basic info about this app's bot
|
||||
* @type {Object}
|
||||
*/
|
||||
this.bot = data.bot;
|
||||
|
||||
/**
|
||||
* The flags for the app
|
||||
* @type {number}
|
||||
*/
|
||||
this.flags = data.flags;
|
||||
|
||||
/**
|
||||
* OAuth2 secret for the application
|
||||
* @type {string}
|
||||
*/
|
||||
this.secret = data.secret;
|
||||
|
||||
if (data.owner) {
|
||||
/**
|
||||
* The owner of this OAuth application
|
||||
* @type {?User}
|
||||
*/
|
||||
this.owner = this.client.users.add(data.owner);
|
||||
}
|
||||
this.owner = this.client.users.add(data.owner);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,34 +111,26 @@ class ClientApplication extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rich presence assets.
|
||||
* @returns {Promise<Object>}
|
||||
* Asset data.
|
||||
* @typedef {Object} ClientAsset
|
||||
* @property {Snowflake} id The asset ID
|
||||
* @property {string} name The asset name
|
||||
* @property {string} type The asset type
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the clients rich presence assets.
|
||||
* @returns {Promise<Array<ClientAsset>>}
|
||||
*/
|
||||
fetchAssets() {
|
||||
const types = Object.keys(ClientApplicationAssetTypes);
|
||||
return this.client.api.oauth2.applications(this.id).assets.get()
|
||||
.then(assets => assets.map(a => ({
|
||||
id: a.id,
|
||||
name: a.name,
|
||||
type: types[a.type - 1],
|
||||
type: AssetTypes[a.type - 1],
|
||||
})));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a rich presence asset.
|
||||
* @param {string} name Name of the asset
|
||||
* @param {Base64Resolvable} data Data of the asset
|
||||
* @param {string} type Type of the asset. `big`, or `small`
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async createAsset(name, data, type) {
|
||||
return this.client.api.oauth2.applications(this.id).assets.post({ data: {
|
||||
name,
|
||||
type: ClientApplicationAssetTypes[type.toUpperCase()],
|
||||
image: await DataResolver.resolveImage(data),
|
||||
} });
|
||||
}
|
||||
|
||||
/**
|
||||
* When concatenated with a string, this automatically returns the application's name instead of the
|
||||
* ClientApplication object.
|
||||
|
||||
Reference in New Issue
Block a user