@hieuxyz/rpc 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -195,8 +195,8 @@ This is the main starting point.
195
195
  - `options.connectionTimeout` (optional): Timeout in milliseconds for the initial connection. Defaults to `30000`.
196
196
  - `client.run()`: Start connecting to Discord Gateway.
197
197
  - `client.rpc`: Access the instance of `HieuxyzRPC` to build the state.
198
+ - `client.createRPC()`: Create a new separate RPC instance (Multi-RPC).
198
199
  - `client.close(force?: boolean)`: Closes the connection to the Discord Gateway.
199
- - `force` (optional, boolean): If `true`, the client closes permanently and will not reconnect.
200
200
 
201
201
  ### Class `HieuxyzRPC`
202
202
 
@@ -205,23 +205,26 @@ Main builder class for RPC.
205
205
  #### Getter Properties
206
206
  - `.largeImageUrl`: Returns the resolved URL for the large image, or `null`.
207
207
  - `.smallImageUrl`: Returns the resolved URL for the small image, or `null`.
208
+ - `.currentStatus`: Returns the current status string (e.g. 'online').
208
209
 
209
210
  #### Setter Methods
210
211
  - `.setName(string)`: Sets the activity name (first line).
211
212
  - `.setDetails(string)`: Sets the activity details (second line).
212
213
  - `.setState(string)`: Sets the activity state (third line).
213
- - `.setTimestamps(start?, end?)`: Sets the start and/or end times.
214
- - `.setParty(current, max)`: Sets the party information.
215
- - `.setLargeImage(RpcImage, text?)`: Sets the large image and its tooltip text.
216
- - `.setSmallImage(RpcImage, text?)`: Sets the small image and its tooltip text.
214
+ - `.setStatus('online' | 'dnd' | 'idle' | 'invisible' | 'offline')`: Sets the user's presence status.
215
+ - `.setType(ActivityType | string | number)`: Sets the activity type (Playing, Listening, etc.).
216
+ - `.setTimestamps(start?, end?)`: Sets the start and/or end times (ms).
217
+ - `.setParty(current, max, id?)`: Sets the party information.
218
+ - `.setLargeImage(RpcImage | string, text?)`: Sets the large image and its tooltip text.
219
+ - `.setSmallImage(RpcImage | string, text?)`: Sets the small image and its tooltip text.
217
220
  - `.setButtons(buttons[])`: Sets up to two clickable buttons. Each button is an object `{ label: string, url: string }`.
221
+ - `.addButton(label, url)`: Adds a single button (max 2).
218
222
  - `.setSecrets({ join?, spectate?, match? })`: Sets secrets for game invites.
219
223
  - `.setSyncId(string)`: Sets the sync ID, used for features like Spotify track syncing.
220
224
  - `.setFlags(number)`: Sets activity flags (e.g., for instanced games). Use the `ActivityFlags` enum.
221
- - `.setPlatform(platform)`: Sets the platform (`'desktop'`, `'xbox'`, etc.).
225
+ - `.setPlatform(platform)`: Sets the platform (`'desktop'`, `'android'`, `'ios'`, `'xbox'`, etc.).
222
226
  - `.setInstance(boolean)`: Marks the activity as a specific, joinable instance.
223
227
  - `.setApplicationId(string)`: Sets a custom Application ID.
224
- - `.setStatus('online' | ...)`: Sets the user's presence status.
225
228
 
226
229
  #### Clearer Methods
227
230
  - `.clearDetails()`: Removes activity details.
@@ -238,16 +241,17 @@ Main builder class for RPC.
238
241
  - `.build()`: Builds and sends the presence payload to Discord.
239
242
  - `.updateRPC()`: Alias for `build()`.
240
243
  - `.clear()`: Clears the Rich Presence from the user's profile and resets the builder.
241
- - `.clearCache()`
242
- - `.destroy()`
244
+ - `.clearCache()`: Clears the internal asset cache.
245
+ - `.destroy()`: Destroys the RPC instance and stops background tasks.
243
246
 
244
247
  ### Types of images
245
248
 
246
249
  - `new ExternalImage(url)`: Use an image from an external URL (will be proxied).
247
250
  - `new LocalImage(filePath, fileName?)`: Upload a photo from your device.
248
- - `new RawImage(assetKey)`: Use an existing asset key directly (e.g., `spotify:track_id`).
251
+ - `new RawImage(assetKey)`: Use an existing asset key directly.
249
252
  - `new DiscordImage(key)`: Use assets already on Discord (e.g., `mp:attachments/...`).
250
253
  - `new ApplicationImage(name)`: Use an asset name from your Discord Application (requires .setApplicationId()).
254
+
251
255
  ## Author
252
256
 
253
257
  Developed by **hieuxyz**.
@@ -104,7 +104,7 @@ class Client {
104
104
  * Displays information about the library.
105
105
  */
106
106
  printAbout() {
107
- const version = '1.2.2';
107
+ const version = '1.2.3';
108
108
  console.log(`
109
109
  _ _
110
110
  | |__ (_) ___ _ ___ ___ _ ______
@@ -103,9 +103,10 @@ export declare class HieuxyzRPC {
103
103
  * Set party information for the activity.
104
104
  * @param {number} currentSize - Current number of players.
105
105
  * @param {number} maxSize - Maximum number of players.
106
+ * @param {string} [id] - Optional custom party ID. Defaults to 'hieuxyz'.
106
107
  * @returns {this}
107
108
  */
108
- setParty(currentSize: number, maxSize: number): this;
109
+ setParty(currentSize: number, maxSize: number, id?: string): this;
109
110
  /**
110
111
  * Set large image and its caption text.
111
112
  * @param {string | RpcImage} source - Image source (URL, asset key, Asset Name or RpcImage object).
@@ -120,8 +121,16 @@ export declare class HieuxyzRPC {
120
121
  * @returns {this}
121
122
  */
122
123
  setSmallImage(source: string | RpcImage, text?: string): this;
124
+ /**
125
+ * Add a single button to the activity.
126
+ * @param {string} label - The text displayed on the button.
127
+ * @param {string} url - The URL opened when the button is clicked.
128
+ * @returns {this}
129
+ */
130
+ addButton(label: string, url: string): this;
123
131
  /**
124
132
  * Set clickable buttons for RPC (up to 2).
133
+ * This will overwrite any existing buttons.
125
134
  * @param {RpcButton[]} buttons - An array of button objects, each with a `label` and `url`.
126
135
  * @returns {this}
127
136
  */
@@ -188,10 +188,11 @@ class HieuxyzRPC {
188
188
  * Set party information for the activity.
189
189
  * @param {number} currentSize - Current number of players.
190
190
  * @param {number} maxSize - Maximum number of players.
191
+ * @param {string} [id] - Optional custom party ID. Defaults to 'hieuxyz'.
191
192
  * @returns {this}
192
193
  */
193
- setParty(currentSize, maxSize) {
194
- this.activity.party = { id: 'hieuxyz', size: [currentSize, maxSize] };
194
+ setParty(currentSize, maxSize, id = 'hieuxyz') {
195
+ this.activity.party = { id: id, size: [currentSize, maxSize] };
195
196
  return this;
196
197
  }
197
198
  /**
@@ -218,8 +219,33 @@ class HieuxyzRPC {
218
219
  this.assets.small_text = this.sanitize(text);
219
220
  return this;
220
221
  }
222
+ /**
223
+ * Add a single button to the activity.
224
+ * @param {string} label - The text displayed on the button.
225
+ * @param {string} url - The URL opened when the button is clicked.
226
+ * @returns {this}
227
+ */
228
+ addButton(label, url) {
229
+ if (!this.activity.buttons) {
230
+ this.activity.buttons = [];
231
+ }
232
+ if (!this.activity.metadata) {
233
+ this.activity.metadata = { button_urls: [] };
234
+ }
235
+ if (!this.activity.metadata.button_urls) {
236
+ this.activity.metadata.button_urls = [];
237
+ }
238
+ if (this.activity.buttons.length >= 2) {
239
+ logger_1.logger.warn('Cannot add more than 2 buttons. Button ignored.');
240
+ return this;
241
+ }
242
+ this.activity.buttons.push(this.sanitize(label, 32));
243
+ this.activity.metadata.button_urls.push(url);
244
+ return this;
245
+ }
221
246
  /**
222
247
  * Set clickable buttons for RPC (up to 2).
248
+ * This will overwrite any existing buttons.
223
249
  * @param {RpcButton[]} buttons - An array of button objects, each with a `label` and `url`.
224
250
  * @returns {this}
225
251
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hieuxyz/rpc",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A Discord Rich Presence library for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",