From 28d4f74b6570706edc769d7698e3925dfad1ead1 Mon Sep 17 00:00:00 2001 From: Kyra Date: Wed, 22 Aug 2018 08:10:55 +0200 Subject: [PATCH] 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 --- src/structures/ClientApplication.js | 79 ++++++++--------------------- typings/index.d.ts | 7 +-- 2 files changed, 21 insertions(+), 65 deletions(-) diff --git a/src/structures/ClientApplication.js b/src/structures/ClientApplication.js index 59dc82671..b08648bdc 100644 --- a/src/structures/ClientApplication.js +++ b/src/structures/ClientApplication.js @@ -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} + * 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>} */ 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. diff --git a/typings/index.d.ts b/typings/index.d.ts index a8cf2cf1e..449c8077d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -228,10 +228,9 @@ declare module 'discord.js' { export class ClientApplication extends Base { constructor(client: Client, data: object); - public bot: object; public botPublic: boolean; public botRequireCodeGrant: boolean; - public cover: string; + public cover?: string; public readonly createdAt: Date; public readonly createdTimestamp: number; public description: string; @@ -239,12 +238,8 @@ declare module 'discord.js' { public id: Snowflake; public name: string; public owner: User; - public redirectURIs: string[]; - public rpcApplicationState: boolean; public rpcOrigins: string[]; - public secret: string; public coverImage(options?: AvatarOptions): string; - public createAsset(name: string, data: Base64Resolvable, type: 'big' | 'small' | 'Big' | 'Small'): Promise; public fetchAssets(): Promise; public iconURL(options?: AvatarOptions): string; public toJSON(): object;