feat(Application): application flags (#5147)

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
Jan
2021-03-31 21:55:12 +02:00
committed by GitHub
parent dedf43288e
commit 06e9d86cb3
9 changed files with 147 additions and 53 deletions

View File

@@ -2,6 +2,7 @@
const Team = require('./Team');
const Application = require('./interfaces/Application');
const ApplicationFlags = require('../util/ApplicationFlags');
/**
* Represents a Client OAuth2 Application.
@@ -11,35 +12,64 @@ class ClientApplication extends Application {
_patch(data) {
super._patch(data);
/**
* The flags this application has
* @type {ApplicationFlags}
*/
this.flags = 'flags' in data ? new ApplicationFlags(data.flags) : this.flags;
/**
* The app's cover image
* @type {?string}
*/
this.cover = data.cover_image || null;
this.cover = data.cover_image ?? this.cover ?? null;
/**
* The app's RPC origins, if enabled
* @type {string[]}
*/
this.rpcOrigins = data.rpc_origins || [];
this.rpcOrigins = data.rpc_origins ?? this.rpcOrigins ?? [];
/**
* If this app's bot requires a code grant when using the OAuth2 flow
* @type {?boolean}
*/
this.botRequireCodeGrant = typeof data.bot_require_code_grant !== 'undefined' ? data.bot_require_code_grant : null;
this.botRequireCodeGrant = data.bot_require_code_grant ?? this.botRequireCodeGrant ?? null;
/**
* If this app's bot is public
* @type {?boolean}
*/
this.botPublic = typeof data.bot_public !== 'undefined' ? data.bot_public : null;
this.botPublic = data.bot_public ?? this.botPublic ?? null;
/**
* The owner of this OAuth application
* @type {?User|Team}
*/
this.owner = data.team ? new Team(this.client, data.team) : data.owner ? this.client.users.add(data.owner) : null;
this.owner = data.team
? new Team(this.client, data.team)
: data.owner
? this.client.users.add(data.owner)
: this.owner ?? null;
}
/**
* Whether this application is partial
* @type {boolean}
* @readonly
*/
get partial() {
return !this.name;
}
/**
* Obtains this application from Discord.
* @returns {Promise<ClientApplication>}
*/
async fetch() {
const app = await this.client.api.oauth2.applications('@me').get();
this._patch(app);
return this;
}
}

View File

@@ -10,15 +10,11 @@ class IntegrationApplication extends Application {
_patch(data) {
super._patch(data);
if (typeof data.bot !== 'undefined') {
/**
* The bot {@link User user} for this application
* @type {?User}
*/
this.bot = this.client.users.add(data.bot);
} else if (!this.bot) {
this.bot = null;
}
/**
* The bot user for this application
* @type {?User}
*/
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null;
}
}

View File

@@ -25,21 +25,21 @@ class Application extends Base {
/**
* The name of the app
* @type {string}
* @type {?string}
*/
this.name = data.name;
this.name = data.name ?? this.name ?? null;
/**
* The app's description
* @type {string}
* @type {?string}
*/
this.description = data.description;
this.description = data.description ?? this.description ?? null;
/**
* The app's icon hash
* @type {string}
* @type {?string}
*/
this.icon = data.icon;
this.icon = data.icon ?? this.icon ?? null;
}
/**
@@ -108,7 +108,7 @@ class Application extends Base {
/**
* When concatenated with a string, this automatically returns the application's name instead of the
* Oauth2Application object.
* @returns {string}
* @returns {?string}
* @example
* // Logs: Application name: My App
* console.log(`Application name: ${application}`);