-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Guild): add includeApplications option for fetchIntegrations (#4762
- Loading branch information
Showing
8 changed files
with
211 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ | |
] | ||
} | ||
}, | ||
"prettier":{ | ||
"prettier": { | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const Application = require('./interfaces/Application'); | ||
|
||
/** | ||
* Represents an Integration's OAuth2 Application. | ||
* @extends {Application} | ||
*/ | ||
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; | ||
} | ||
} | ||
} | ||
|
||
module.exports = IntegrationApplication; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
'use strict'; | ||
|
||
const { ClientApplicationAssetTypes, Endpoints } = require('../../util/Constants'); | ||
const Snowflake = require('../../util/Snowflake'); | ||
const Base = require('../Base'); | ||
|
||
const AssetTypes = Object.keys(ClientApplicationAssetTypes); | ||
|
||
/** | ||
* Represents an OAuth2 Application. | ||
* @abstract | ||
*/ | ||
class Application extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* The ID of the app | ||
* @type {Snowflake} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The name of the app | ||
* @type {string} | ||
*/ | ||
this.name = data.name; | ||
|
||
/** | ||
* The app's description | ||
* @type {string} | ||
*/ | ||
this.description = data.description; | ||
|
||
/** | ||
* The app's icon hash | ||
* @type {string} | ||
*/ | ||
this.icon = data.icon; | ||
} | ||
|
||
/** | ||
* The timestamp the app was created at | ||
* @type {number} | ||
* @readonly | ||
*/ | ||
get createdTimestamp() { | ||
return Snowflake.deconstruct(this.id).timestamp; | ||
} | ||
|
||
/** | ||
* The time the app was created at | ||
* @type {Date} | ||
* @readonly | ||
*/ | ||
get createdAt() { | ||
return new Date(this.createdTimestamp); | ||
} | ||
|
||
/** | ||
* A link to the application's icon. | ||
* @param {ImageURLOptions} [options={}] Options for the Image URL | ||
* @returns {?string} URL to the icon | ||
*/ | ||
iconURL({ format, size } = {}) { | ||
if (!this.icon) return null; | ||
return this.client.rest.cdn.AppIcon(this.id, this.icon, { format, size }); | ||
} | ||
|
||
/** | ||
* A link to this application's cover image. | ||
* @param {ImageURLOptions} [options={}] Options for the Image URL | ||
* @returns {?string} URL to the cover image | ||
*/ | ||
coverImage({ format, size } = {}) { | ||
if (!this.cover) return null; | ||
return Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.cover, { format, size }); | ||
} | ||
|
||
/** | ||
* Asset data. | ||
* @typedef {Object} ApplicationAsset | ||
* @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<ApplicationAsset>>} | ||
*/ | ||
fetchAssets() { | ||
return this.client.api.oauth2 | ||
.applications(this.id) | ||
.assets.get() | ||
.then(assets => | ||
assets.map(a => ({ | ||
id: a.id, | ||
name: a.name, | ||
type: AssetTypes[a.type - 1], | ||
})), | ||
); | ||
} | ||
|
||
/** | ||
* When concatenated with a string, this automatically returns the application's name instead of the | ||
* Oauth2Application object. | ||
* @returns {string} | ||
* @example | ||
* // Logs: Application name: My App | ||
* console.log(`Application name: ${application}`); | ||
*/ | ||
toString() { | ||
return this.name; | ||
} | ||
|
||
toJSON() { | ||
return super.toJSON({ createdTimestamp: true }); | ||
} | ||
} | ||
|
||
module.exports = Application; |
Oops, something went wrong.