From 3e84e501b7e0fe9657c07f1bb3a917aa18a9fd1b Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:19:09 +0700 Subject: [PATCH] fix: rpc --- src/structures/Presence.js | 26 +++++++++++++++++++++----- typings/index.d.ts | 5 +---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/structures/Presence.js b/src/structures/Presence.js index 5cd9f90..8e46fd9 100644 --- a/src/structures/Presence.js +++ b/src/structures/Presence.js @@ -404,7 +404,10 @@ class Activity { } toJSON(...props) { - return Util.flatten(this, ...props); + return { + ...Util.flatten(this, ...props), + type: typeof this.type === 'number' ? this.type : ActivityTypes[this.type], + }; } } @@ -692,7 +695,6 @@ class RichPresence extends Activity { * Set the large image of this activity * @param {?RichPresenceImage} image The large image asset's id * @returns {RichPresence} - * @deprecated */ setAssetsLargeImage(image) { this.assets.setLargeImage(image); @@ -703,7 +705,6 @@ class RichPresence extends Activity { * Set the small image of this activity * @param {?RichPresenceImage} image The small image asset's id * @returns {RichPresence} - * @deprecated */ setAssetsSmallImage(image) { this.assets.setSmallImage(image); @@ -714,7 +715,6 @@ class RichPresence extends Activity { * Hover text for the large image * @param {string} text Assets text * @returns {RichPresence} - * @deprecated */ setAssetsLargeText(text) { this.assets.setLargeText(text); @@ -725,7 +725,6 @@ class RichPresence extends Activity { * Hover text for the small image * @param {string} text Assets text * @returns {RichPresence} - * @deprecated */ setAssetsSmallText(text) { this.assets.setSmallText(text); @@ -879,6 +878,16 @@ class RichPresence extends Activity { return this; } + /** + * Secrets for rich presence joining and spectating (send-only) + * @param {?string} join Secrets for rich presence joining + * @returns {RichPresence} + */ + setJoinSecret(join) { + this.secrets.join = join; + return this; + } + /** * Add a button to the rich presence * @param {string} name The name of the button @@ -1057,6 +1066,13 @@ class SpotifyRPC extends RichPresence { this.metadata.context_uri = `spotify:album:${id}`; return this; } + + toJSON() { + return { + ...super.toJSON({ id: false, emoji: false, platform: false, buttons: false }), + session_id: this.presence.client.sessionId, + }; + } } exports.Presence = Presence; diff --git a/typings/index.d.ts b/typings/index.d.ts index d085a94..425402d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -176,13 +176,9 @@ export interface RichButton { export class RichPresence extends Activity { public constructor(client: Client, data?: object); public metadata: RichPresenceMetadata; - /** @deprecated */ public setAssetsLargeImage(image?: string): this; - /** @deprecated */ public setAssetsLargeText(text?: string): this; - /** @deprecated */ public setAssetsSmallImage(image?: string): this; - /** @deprecated */ public setAssetsSmallText(text?: string): this; public setName(name?: string): this; public setURL(url?: string): this; @@ -195,6 +191,7 @@ export class RichPresence extends Activity { public setEndTimestamp(timestamp: Date | number | null): this; public setButtons(...button: RichButton[]): this; public addButton(name: string, url: string): this; + public setJoinSecret(join?: string): this; public static getExternal( client: Client, applicationId: Snowflake,