@hieuxyz/rpc 1.0.8 → 1.0.9

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
@@ -43,7 +43,7 @@ DISCORD_USER_TOKEN="YOUR_DISCORD_USER_TOKEN_HERE"
43
43
 
44
44
  ```typescript
45
45
  import * as path from 'path';
46
- import { Client, LocalImage, logger } from '@hieuxyz/rpc';
46
+ import { Client, LocalImage, logger } from '../src';
47
47
 
48
48
  async function start() {
49
49
  const token = process.env.DISCORD_USER_TOKEN;
@@ -73,25 +73,26 @@ async function start() {
73
73
  .setSmallImage(new LocalImage(path.join(__dirname, 'vscode.png')), "VS Code");
74
74
 
75
75
  await client.rpc.build();
76
+ logger.info("Initial RPC has been set!");
76
77
 
77
- setTimeout(async () => {
78
- logger.info("Updating RPC details dynamically...");
78
+ setTimeout(() => {
79
+ logger.info("Clearing RPC and resetting builder...");
80
+ client.rpc.clear();
79
81
 
80
- // Change the necessary information
81
82
  client.rpc
82
- .setDetails("Reviewing pull requests")
83
- .setState("PR #01: Feature enhancement")
84
- .setParty(2, 5);
85
-
86
- await client.rpc.updateRPC();
83
+ .setName("On a break")
84
+ .setDetails("Thinking about the next feature")
85
+ .setLargeImage("mp:external/dZwPAoMNVxT5qYqecH3Mfgxv1RQEdtGBU8nAspOcAo4/https/c.tenor.com/fvuYGhI1vgUAAAAC/tenor.gif", "Coffee Time");
87
86
 
88
- logger.info("RPC has been dynamically updated!");
87
+ client.rpc.build();
88
+ logger.info("A new RPC has been set after clearing.");
89
89
 
90
- }, 15000);
90
+ }, 20000);
91
91
 
92
92
  process.on('SIGINT', () => {
93
93
  logger.info("SIGINT received. Closing connection...");
94
- client.close();
94
+ client.rpc.clear();
95
+ client.close(true);
95
96
  process.exit(0);
96
97
  });
97
98
  }
@@ -159,7 +160,8 @@ Main builder class for RPC.
159
160
  - `.setButtons(buttons[])`: Set buttons (up to 2).
160
161
  - `.setPlatform(platform)`: Lay the platform (`'desktop'`, `'xbox'`, `'ps5'`).
161
162
  - `.build()`: First RPC send.
162
- - `.updateRPC()`: Send updates to an existing RPC.(it just call build() lol)
163
+ - `.updateRPC()`: Send updates to an existing RPC.(it just call build() lol).
164
+ - `.clear()`: Clears the current Rich Presence from the user's profile and resets the builder to its default state.
163
165
 
164
166
  ### Types of images
165
167
 
@@ -125,5 +125,12 @@ export declare class HieuxyzRPC {
125
125
  * @returns {Promise<void>}
126
126
  */
127
127
  updateRPC(): Promise<void>;
128
+ /**
129
+ * Clears the current Rich Presence from Discord and resets the builder state.
130
+ * This sends an empty activity payload to Discord and then resets all configured
131
+ * options (name, details, images, etc.) to their default values, allowing you
132
+ * to build a new presence from scratch.
133
+ */
134
+ clear(): void;
128
135
  }
129
136
  export {};
@@ -300,5 +300,26 @@ class HieuxyzRPC {
300
300
  async updateRPC() {
301
301
  await this.build();
302
302
  }
303
+ /**
304
+ * Clears the current Rich Presence from Discord and resets the builder state.
305
+ * This sends an empty activity payload to Discord and then resets all configured
306
+ * options (name, details, images, etc.) to their default values, allowing you
307
+ * to build a new presence from scratch.
308
+ */
309
+ clear() {
310
+ const clearPayload = {
311
+ since: 0,
312
+ activities: [],
313
+ status: this.status,
314
+ afk: true,
315
+ };
316
+ this.websocket.sendActivity(clearPayload);
317
+ logger_1.logger.info("Rich Presence cleared from Discord.");
318
+ this.activity = {};
319
+ this.assets = {};
320
+ this.applicationId = '1416676323459469363'; // Reset to default
321
+ this.platform = 'desktop'; // Reset to default
322
+ logger_1.logger.info("RPC builder has been reset to its initial state.");
323
+ }
303
324
  }
304
325
  exports.HieuxyzRPC = HieuxyzRPC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hieuxyz/rpc",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A Discord Rich Presence library for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",