patched discord rpc for refresh token

This commit is contained in:
GW_MC
2026-01-23 18:02:03 +08:00
parent 4e246637fb
commit b972f10e60
4 changed files with 59 additions and 4 deletions

View File

@@ -22,5 +22,11 @@
"@types/node": "^25.0.10", "@types/node": "^25.0.10",
"tsx": "^4.21.0", "tsx": "^4.21.0",
"typescript": "^5.9.3" "typescript": "^5.9.3"
},
"pnpm": {
"patchedDependencies": {
"discord-rpc@4.0.1": "patches/discord-rpc@4.0.1.patch",
"@types/discord-rpc@4.0.10": "patches/@types__discord-rpc@4.0.10.patch"
}
} }
} }

View File

@@ -0,0 +1,14 @@
diff --git a/index.d.ts b/index.d.ts
index 04480d88d0cd2e21f8a7e2ef9878d6984b14fff5..81285e7e54381362925cc93ccd3f51ff087b5763 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -52,6 +52,9 @@ export class BaseClient extends EventEmitter {}
* The main hub for interacting with Discord RPC
*/
export class Client extends BaseClient {
+ accessToken: string | null;
+ refreshToken: string | null;
+ accessTokenExpiresAt: number | null;
/**
* @param options Options for the client.
* You must provide a transport

View File

@@ -0,0 +1,27 @@
diff --git a/src/client.js b/src/client.js
index 0ff29daa9ac1cd4f406944b3e195738d520b2c57..90ef5dc7228e8b1678f72e2573b42bd222a527c1 100644
--- a/src/client.js
+++ b/src/client.js
@@ -32,6 +32,8 @@ class RPCClient extends EventEmitter {
this.options = options;
this.accessToken = null;
+ this.refreshToken = null;
+ this.accessTokenExpiresAt = null;
this.clientId = null;
/**
@@ -222,6 +224,13 @@ class RPCClient extends EventEmitter {
}),
});
+ const {
+ access_token, refresh_token, expires_in
+ } = response;
+
+ this.refreshToken = refresh_token;
+ this.accessTokenExpiresAt = Date.now() + (expires_in * 1000);
+
return response.access_token;
}

16
pnpm-lock.yaml generated
View File

@@ -4,6 +4,14 @@ settings:
autoInstallPeers: true autoInstallPeers: true
excludeLinksFromLockfile: false excludeLinksFromLockfile: false
patchedDependencies:
'@types/discord-rpc@4.0.10':
hash: jkq6l3q3zsza22tiqsryj6war4
path: patches/@types__discord-rpc@4.0.10.patch
discord-rpc@4.0.1:
hash: sqrsp2dfxm56uqm2hxrxu3bbpi
path: patches/discord-rpc@4.0.1.patch
importers: importers:
.: .:
@@ -13,14 +21,14 @@ importers:
version: 1.13.2 version: 1.13.2
discord-rpc: discord-rpc:
specifier: ^4.0.1 specifier: ^4.0.1
version: 4.0.1 version: 4.0.1(patch_hash=sqrsp2dfxm56uqm2hxrxu3bbpi)
dotenv: dotenv:
specifier: ^17.2.3 specifier: ^17.2.3
version: 17.2.3 version: 17.2.3
devDependencies: devDependencies:
'@types/discord-rpc': '@types/discord-rpc':
specifier: ^4.0.10 specifier: ^4.0.10
version: 4.0.10 version: 4.0.10(patch_hash=jkq6l3q3zsza22tiqsryj6war4)
'@types/node': '@types/node':
specifier: ^25.0.10 specifier: ^25.0.10
version: 25.0.10 version: 25.0.10
@@ -450,7 +458,7 @@ snapshots:
'@esbuild/win32-x64@0.27.2': '@esbuild/win32-x64@0.27.2':
optional: true optional: true
'@types/discord-rpc@4.0.10': '@types/discord-rpc@4.0.10(patch_hash=jkq6l3q3zsza22tiqsryj6war4)':
dependencies: dependencies:
'@types/events': 3.0.3 '@types/events': 3.0.3
@@ -486,7 +494,7 @@ snapshots:
delayed-stream@1.0.0: {} delayed-stream@1.0.0: {}
discord-rpc@4.0.1: discord-rpc@4.0.1(patch_hash=sqrsp2dfxm56uqm2hxrxu3bbpi):
dependencies: dependencies:
node-fetch: 2.7.0 node-fetch: 2.7.0
ws: 7.5.10 ws: 7.5.10