spotify stuff (#2314)

This commit is contained in:
Gus Caplan
2018-02-02 12:45:18 -06:00
committed by Isabella
parent 234648bd2a
commit bd1bf11ed0
2 changed files with 24 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
const { ActivityTypes } = require('../util/Constants');
const { ActivityTypes, ActivityFlags } = require('../util/Constants');
/**
* Represents a user's presence.
@@ -118,6 +118,17 @@ class Activity {
* @type {?RichPresenceAssets}
*/
this.assets = data.assets ? new RichPresenceAssets(this, data.assets) : null;
this.syncID = data.sync_id;
this._flags = data.flags;
}
get flags() {
const flags = [];
for (const [name, flag] of Object.entries(ActivityFlags)) {
if ((this._flags & flag) === flag) flags.push(name);
}
return flags;
}
/**
@@ -201,6 +212,9 @@ class RichPresenceAssets {
*/
largeImageURL({ format, size } = {}) {
if (!this.largeImage) return null;
if (/^spotify:/.test(this.largeImage)) {
return `https://i.scdn.co/image/${this.largeImage.slice(8)}`;
}
return this.activity.presence.client.rest.cdn
.AppAsset(this.activity.applicationID, this.largeImage, { format, size });
}