diff --git a/src/client/Client.js b/src/client/Client.js index 69986e071..ae40d6774 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -16,7 +16,7 @@ const VoiceRegion = require('../structures/VoiceRegion'); const Webhook = require('../structures/Webhook'); const User = require('../structures/User'); const Invite = require('../structures/Invite'); -const OAuth2Application = require('../structures/OAuth2Application'); +const ClientApplication = require('../structures/ClientApplication'); const ShardClientUtil = require('../sharding/ShardClientUtil'); const VoiceBroadcast = require('./voice/VoiceBroadcast'); const { Error, TypeError, RangeError } = require('../errors'); @@ -415,7 +415,7 @@ class Client extends EventEmitter { */ fetchApplication(id = '@me') { return this.api.oauth2.applications(id).get() - .then(app => new OAuth2Application(this, app)); + .then(app => new ClientApplication(this, app)); } /** diff --git a/src/index.js b/src/index.js index face2be00..217bb1494 100644 --- a/src/index.js +++ b/src/index.js @@ -46,8 +46,7 @@ module.exports = { MessageEmbed: require('./structures/MessageEmbed'), MessageMentions: require('./structures/MessageMentions'), MessageReaction: require('./structures/MessageReaction'), - OAuth2Application: require('./structures/OAuth2Application'), - ClientOAuth2Application: require('./structures/OAuth2Application'), + ClientApplication: require('./structures/ClientApplication'), PartialGuild: require('./structures/PartialGuild'), PartialGuildChannel: require('./structures/PartialGuildChannel'), PermissionOverwrites: require('./structures/PermissionOverwrites'), diff --git a/src/structures/OAuth2Application.js b/src/structures/ClientApplication.js similarity index 80% rename from src/structures/OAuth2Application.js rename to src/structures/ClientApplication.js index 15297f60e..6e00c654e 100644 --- a/src/structures/OAuth2Application.js +++ b/src/structures/ClientApplication.js @@ -126,7 +126,36 @@ class OAuth2Application { */ iconURL({ format, size } = {}) { if (!this.icon) return null; - return Constants.Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.icon, format, size); + return Constants.Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.icon, { format, size }); + } + + /** + * Get rich presence assets + * @returns {Promise} + */ + fetchAssets() { + return this.client.api.applications(this.id).assets.get() + .then(assets => assets.map(a => ({ + id: a.id, + name: a.name, + type: Object.keys(Constants.ClientApplicationAssetTypes)[a.type - 1], + }))); + } + + /** + * Create 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} + */ + createAsset(name, data, type) { + return this.client.resolveBase64(data).then(b64 => + this.client.api.applications(this.id).assets.post({ data: { + name, + data: b64, + type: Constants.ClientApplicationAssetTypes[type.toUpperCase()], + } })); } /** diff --git a/src/structures/Message.js b/src/structures/Message.js index 97584d84d..440552f95 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -3,6 +3,7 @@ const Attachment = require('./MessageAttachment'); const Embed = require('./MessageEmbed'); const MessageReaction = require('./MessageReaction'); const ReactionCollector = require('./ReactionCollector'); +const ClientApplication = require('./ClientApplication'); const Util = require('../util/Util'); const Collection = require('../util/Collection'); const Constants = require('../util/Constants'); @@ -137,6 +138,21 @@ class Message { */ this.webhookID = data.webhook_id || null; + /** + * Supplimental application information for group activities + * @type {?ClientApplication} + */ + this.application = data.application ? new ClientApplication(this.client, data.application) : null; + + /** + * Group activity + * @type {?Object} + */ + this.activiy = data.activity ? { + partyID: data.activity.party_id, + type: data.activity.type, + } : null; + /** * Whether this message is a hit in a search * @type {?boolean} diff --git a/src/util/Constants.js b/src/util/Constants.js index 0238ed483..c23af6adf 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -103,9 +103,10 @@ const AllowedImageSizes = [ 2048, ]; -function checkImage({ size, format }) { +function makeImageUrl(root, { format = 'webp', size } = {}) { if (format && !AllowedImageFormats.includes(format)) throw new Error('IMAGE_FORMAT', format); if (size && !AllowedImageSizes.includes(size)) throw new RangeError('IMAGE_SIZE', size); + return `${root}.${format}${size ? `?size=${size}` : ''}`; } exports.Endpoints = { @@ -116,25 +117,16 @@ exports.Endpoints = { DefaultAvatar: number => `${root}/embed/avatars/${number}.png`, Avatar: (userID, hash, format = 'default', size) => { if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp'; - checkImage({ size, format }); - return `${root}/avatars/${userID}/${hash}.${format}${size ? `?size=${size}` : ''}`; - }, - Icon: (guildID, hash, format = 'webp', size) => { - checkImage({ size, format }); - return `${root}/icons/${guildID}/${hash}.${format}${size ? `?size=${size}` : ''}`; - }, - AppIcon: (clientID, hash, format = 'webp', size) => { - checkImage({ size, format }); - return `${root}/app-icons/${clientID}/${hash}.${format}${size ? `?size=${size}` : ''}`; - }, - GDMIcon: (channelID, hash, format = 'webp', size) => { - checkImage({ size, format }); - return `${root}/channel-icons/${channelID}/${hash}.${format}${size ? `?size=${size}` : ''}`; - }, - Splash: (guildID, hash, format = 'webp', size) => { - checkImage({ size, format }); - return `${root}/splashes/${guildID}/${hash}.${format}${size ? `?size=${size}` : ''}`; + return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size }); }, + Icon: (guildID, hash, format = 'webp', size) => + makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size }), + AppIcon: (clientID, hash, { format = 'webp', size } = {}) => + makeImageUrl(`${root}/app-icons/${clientID}/${hash}`, { size, format }), + GDMIcon: (channelID, hash, format = 'webp', size) => + makeImageUrl(`${root}/channel-icons/${channelID}/${hash}`, { size, format }), + Splash: (guildID, hash, format = 'webp', size) => + makeImageUrl(`${root}/splashes/${guildID}/${hash}`, { size, format }), }; }, invite: (root, code) => `${root}/${code}`, @@ -570,6 +562,11 @@ exports.UserFlags = { HYPESQUAD: 1 << 2, }; +exports.ClientApplicationAssetTypes = { + SMALL: 1, + BIG: 2, +}; + exports.Colors = { DEFAULT: 0x000000, AQUA: 0x1ABC9C,