mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23: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 Snowflake = require('../util/Snowflake');
|
||||||
const { ClientApplicationAssetTypes, Endpoints } = require('../util/Constants');
|
const { ClientApplicationAssetTypes, Endpoints } = require('../util/Constants');
|
||||||
const DataResolver = require('../util/DataResolver');
|
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
|
|
||||||
|
const AssetTypes = Object.keys(ClientApplicationAssetTypes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Client OAuth2 Application.
|
* Represents a Client OAuth2 Application.
|
||||||
* @extends {Base}
|
* @extends {Base}
|
||||||
@@ -39,22 +40,16 @@ class ClientApplication extends Base {
|
|||||||
this.icon = data.icon;
|
this.icon = data.icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The app's cover image hash
|
* The app's cover image
|
||||||
* @type {?string}
|
* @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[]}
|
* @type {?string[]}
|
||||||
*/
|
*/
|
||||||
this.rpcOrigins = data.rpc_origins;
|
this.rpcOrigins = data.rpc_origins || [];
|
||||||
|
|
||||||
/**
|
|
||||||
* The app's redirect URIs
|
|
||||||
* @type {string[]}
|
|
||||||
*/
|
|
||||||
this.redirectURIs = data.redirect_uris;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this app's bot requires a code grant when using the OAuth2 flow
|
* 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;
|
this.botPublic = data.bot_public;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this app can use rpc
|
* The owner of this OAuth application
|
||||||
* @type {boolean}
|
* @type {User}
|
||||||
*/
|
*/
|
||||||
this.rpcApplicationState = data.rpc_application_state;
|
this.owner = this.client.users.add(data.owner);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,34 +111,26 @@ class ClientApplication extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get rich presence assets.
|
* Asset data.
|
||||||
* @returns {Promise<Object>}
|
* @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() {
|
fetchAssets() {
|
||||||
const types = Object.keys(ClientApplicationAssetTypes);
|
|
||||||
return this.client.api.oauth2.applications(this.id).assets.get()
|
return this.client.api.oauth2.applications(this.id).assets.get()
|
||||||
.then(assets => assets.map(a => ({
|
.then(assets => assets.map(a => ({
|
||||||
id: a.id,
|
id: a.id,
|
||||||
name: a.name,
|
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
|
* When concatenated with a string, this automatically returns the application's name instead of the
|
||||||
* ClientApplication object.
|
* ClientApplication object.
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -228,10 +228,9 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class ClientApplication extends Base {
|
export class ClientApplication extends Base {
|
||||||
constructor(client: Client, data: object);
|
constructor(client: Client, data: object);
|
||||||
public bot: object;
|
|
||||||
public botPublic: boolean;
|
public botPublic: boolean;
|
||||||
public botRequireCodeGrant: boolean;
|
public botRequireCodeGrant: boolean;
|
||||||
public cover: string;
|
public cover?: string;
|
||||||
public readonly createdAt: Date;
|
public readonly createdAt: Date;
|
||||||
public readonly createdTimestamp: number;
|
public readonly createdTimestamp: number;
|
||||||
public description: string;
|
public description: string;
|
||||||
@@ -239,12 +238,8 @@ declare module 'discord.js' {
|
|||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
public name: string;
|
public name: string;
|
||||||
public owner: User;
|
public owner: User;
|
||||||
public redirectURIs: string[];
|
|
||||||
public rpcApplicationState: boolean;
|
|
||||||
public rpcOrigins: string[];
|
public rpcOrigins: string[];
|
||||||
public secret: string;
|
|
||||||
public coverImage(options?: AvatarOptions): string;
|
public coverImage(options?: AvatarOptions): string;
|
||||||
public createAsset(name: string, data: Base64Resolvable, type: 'big' | 'small' | 'Big' | 'Small'): Promise<object>;
|
|
||||||
public fetchAssets(): Promise<ClientApplicationAsset>;
|
public fetchAssets(): Promise<ClientApplicationAsset>;
|
||||||
public iconURL(options?: AvatarOptions): string;
|
public iconURL(options?: AvatarOptions): string;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
|
|||||||
Reference in New Issue
Block a user