Setup filtering for discordrpc
This commit is contained in:
parent
8da0ebed97
commit
b4e0869215
2 changed files with 44 additions and 15 deletions
|
@ -90,6 +90,44 @@ export default class DiscordRichPresence {
|
||||||
}).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
}).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the Discord activity object
|
||||||
|
*/
|
||||||
|
private filterActivity(activity: any, attributes: any): Object {
|
||||||
|
|
||||||
|
// Checks if the name is greater than 128 because some songs can be that long
|
||||||
|
if (activity.details && activity.details.length > 128) {
|
||||||
|
activity.details = activity.details.substring(0, 125) + '...'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check large image
|
||||||
|
if (activity.largeImageKey === null || activity.largeImageKey === ""){
|
||||||
|
activity.largeImageKey = "cider";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timestamp
|
||||||
|
if (new Date(attributes.endTime).getTime() < 0) {
|
||||||
|
delete activity.startTime
|
||||||
|
delete activity.endTime
|
||||||
|
}
|
||||||
|
|
||||||
|
// not sure
|
||||||
|
if (!attributes.artistName) {
|
||||||
|
delete activity.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activity.largeImageText || activity.largeImageText.length < 2) {
|
||||||
|
delete activity.largeImageText
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.buttons.forEach((key: {label: string, url: string}, value: Number) => {
|
||||||
|
if (key.url.endsWith('undefined') || key.url.includes('undefined')) {
|
||||||
|
activity.buttons.splice(key, 1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return activity
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the activity of the client
|
* Sets the activity of the client
|
||||||
* @param {object} attributes
|
* @param {object} attributes
|
||||||
|
@ -105,27 +143,18 @@ export default class DiscordRichPresence {
|
||||||
this._activity = {
|
this._activity = {
|
||||||
details: attributes.name,
|
details: attributes.name,
|
||||||
state: `${attributes.artistName ? `by ${attributes.artistName}` : ''}`,
|
state: `${attributes.artistName ? `by ${attributes.artistName}` : ''}`,
|
||||||
startTimestamp: ((new Date(attributes.endTime).getTime() < 0) ? null : attributes.startTime),
|
startTimestamp: attributes.startTime,
|
||||||
endTimestamp: ((new Date(attributes.endTime).getTime() < 0) ? null : attributes.endTime),
|
endTimestamp: attributes.endTime,
|
||||||
largeImageKey: (attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024')) ?? 'cider',
|
largeImageKey: attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024'),
|
||||||
largeImageText: attributes.albumName,
|
largeImageText: attributes.albumName,
|
||||||
instance: false, // Whether the activity is in a game session
|
instance: false, // Whether the activity is in a game session
|
||||||
|
|
||||||
buttons: [
|
buttons: [
|
||||||
{label: "Listen on Cider", url: attributes.url.cider},
|
{label: "Listen on Cider", url: attributes.url.cider},
|
||||||
{label: "View on Apple Music", url: attributes.url.appleMusic},
|
{label: "View on Apple Music", url: attributes.url.appleMusic},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._activity = this.filterActivity(this._activity, attributes)
|
||||||
// Checks if the name is greater than 128 because some songs can be that long
|
|
||||||
if (this._activity.details && this._activity.details.length > 128) {
|
|
||||||
this._activity.details = this._activity.details.substring(0, 125) + '...'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._activity.largeImageKey == null || this._activity.largeImageKey == ""){
|
|
||||||
this._activity.largeImageKey = "cider";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if its pausing (false) or playing (true)
|
// Check if its pausing (false) or playing (true)
|
||||||
if (!attributes.status) {
|
if (!attributes.status) {
|
||||||
|
|
|
@ -51,8 +51,8 @@ const MusicKitInterop = {
|
||||||
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
|
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
|
||||||
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
||||||
attributes.url = {
|
attributes.url = {
|
||||||
cider: "cider://play/s/" + nowPlayingItem?._songId ?? 'no-id-found',
|
cider: `cider://play/s/${nowPlayingItem?._songId ?? 'no-id-found'}`,
|
||||||
appleMusic: "https://music.apple.com/"+ mk.storefrontId +"/song/" + nowPlayingItem?._songId ?? 'no-id-found'
|
appleMusic: attributes.websiteUrl ? attributes.websiteUrl : `https://music.apple.com/${mk.storefrontId}/song/${nowPlayingItem?._songId ?? 'no-id-found'}`
|
||||||
}
|
}
|
||||||
if (attributes.playParams.id === 'no-id-found') {
|
if (attributes.playParams.id === 'no-id-found') {
|
||||||
attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found';
|
attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue