feat(richpresenceassets): add YouTube and custom image support (#7184)

This commit is contained in:
Commandtechno
2022-01-08 05:40:35 -06:00
committed by GitHub
parent 95f8375d42
commit d06d70ccf2

View File

@@ -351,13 +351,21 @@ class RichPresenceAssets {
* @returns {?string} * @returns {?string}
*/ */
smallImageURL({ format, size } = {}) { smallImageURL({ format, size } = {}) {
return ( if (!this.smallImage) return null;
this.smallImage && if (this.smallImage.includes(':')) {
this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.smallImage, { const [platform, id] = this.smallImage.split(':');
format, switch (platform) {
size, case 'mp':
}) return `https://media.discordapp.net/${id}`;
); default:
return null;
}
}
return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.smallImage, {
format,
size,
});
} }
/** /**
@@ -367,11 +375,22 @@ class RichPresenceAssets {
*/ */
largeImageURL({ format, size } = {}) { largeImageURL({ format, size } = {}) {
if (!this.largeImage) return null; if (!this.largeImage) return null;
if (/^spotify:/.test(this.largeImage)) { if (this.largeImage.includes(':')) {
return `https://i.scdn.co/image/${this.largeImage.slice(8)}`; const [platform, id] = this.largeImage.split(':');
} else if (/^twitch:/.test(this.largeImage)) { switch (platform) {
return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${this.largeImage.slice(7)}.png`; case 'mp':
return `https://media.discordapp.net/${id}`;
case 'spotify':
return `https://i.scdn.co/image/${id}`;
case 'youtube':
return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
case 'twitch':
return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
default:
return null;
}
} }
return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.largeImage, { return this.activity.presence.client.rest.cdn.AppAsset(this.activity.applicationId, this.largeImage, {
format, format,
size, size,