magmastream 2.10.2-alpha.3 → 2.10.2-alpha.5
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.
|
@@ -143,13 +143,13 @@ export declare class Manager extends EventEmitter {
|
|
|
143
143
|
*/
|
|
144
144
|
get useableNode(): Node;
|
|
145
145
|
/**
|
|
146
|
-
* Handles the shutdown of the process by saving all active players' states
|
|
146
|
+
* Handles the shutdown of the process by saving all active players' states.
|
|
147
147
|
* This function is called when the process is about to exit.
|
|
148
148
|
* It iterates through all players and calls {@link savePlayerState} to save their states.
|
|
149
|
-
*
|
|
150
|
-
*
|
|
149
|
+
* After saving, it exits the process.
|
|
150
|
+
* @param stopProcess - A function to stop the process.
|
|
151
151
|
*/
|
|
152
|
-
handleShutdown(): Promise<void>;
|
|
152
|
+
handleShutdown(stopProcess?: () => Promise<void>): Promise<void>;
|
|
153
153
|
/**
|
|
154
154
|
* Parses a YouTube title into a clean title and author.
|
|
155
155
|
* @param title - The original title of the YouTube video.
|
|
@@ -15,6 +15,7 @@ const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
|
|
|
15
15
|
const Enums_1 = require("./Enums");
|
|
16
16
|
const package_json_1 = require("../../package.json");
|
|
17
17
|
const MagmastreamError_1 = require("./MagmastreamError");
|
|
18
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
18
19
|
/**
|
|
19
20
|
* The main hub for interacting with Lavalink and using Magmastream.
|
|
20
21
|
*/
|
|
@@ -178,13 +179,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
178
179
|
this.options.clusterId = clusterId;
|
|
179
180
|
}
|
|
180
181
|
if (this.options.stateStorage.type === Enums_1.StateStorageType.Redis) {
|
|
181
|
-
|
|
182
|
-
this.redis = new ioredis_1.default({
|
|
183
|
-
host: config.host,
|
|
184
|
-
port: Number(config.port),
|
|
185
|
-
password: config.password,
|
|
186
|
-
db: config.db ?? 0,
|
|
187
|
-
});
|
|
182
|
+
this.redis = new ioredis_1.default(lodash_1.default.omit(this.options.stateStorage.redisConfig, "prefix"));
|
|
188
183
|
}
|
|
189
184
|
const results = await Promise.allSettled([...this.nodes.values()].map(async (node) => {
|
|
190
185
|
await node.connect();
|
|
@@ -741,13 +736,13 @@ class Manager extends events_1.EventEmitter {
|
|
|
741
736
|
return this.options.enablePriorityMode ? this.priorityNode : this.options.useNode === Enums_1.UseNodeOptions.LeastLoad ? this.leastLoadNode.first() : this.leastPlayersNode.first();
|
|
742
737
|
}
|
|
743
738
|
/**
|
|
744
|
-
* Handles the shutdown of the process by saving all active players' states
|
|
739
|
+
* Handles the shutdown of the process by saving all active players' states.
|
|
745
740
|
* This function is called when the process is about to exit.
|
|
746
741
|
* It iterates through all players and calls {@link savePlayerState} to save their states.
|
|
747
|
-
*
|
|
748
|
-
*
|
|
742
|
+
* After saving, it exits the process.
|
|
743
|
+
* @param stopProcess - A function to stop the process.
|
|
749
744
|
*/
|
|
750
|
-
async handleShutdown() {
|
|
745
|
+
async handleShutdown(stopProcess) {
|
|
751
746
|
this.unloadPlugins();
|
|
752
747
|
console.warn("\x1b[31m%s\x1b[0m", "MAGMASTREAM WARNING: Shutting down! Please wait, saving active players...");
|
|
753
748
|
try {
|
|
@@ -768,9 +763,12 @@ class Manager extends events_1.EventEmitter {
|
|
|
768
763
|
}
|
|
769
764
|
});
|
|
770
765
|
await Promise.allSettled(savePromises);
|
|
771
|
-
setTimeout(() => {
|
|
766
|
+
setTimeout(async () => {
|
|
772
767
|
console.warn("\x1b[32m%s\x1b[0m", "MAGMASTREAM INFO: Shutting down complete, exiting...");
|
|
773
|
-
|
|
768
|
+
if (stopProcess)
|
|
769
|
+
await stopProcess();
|
|
770
|
+
else
|
|
771
|
+
process.exit(0);
|
|
774
772
|
}, 500);
|
|
775
773
|
}
|
|
776
774
|
catch (err) {
|
package/dist/structures/Rest.js
CHANGED
|
@@ -107,6 +107,7 @@ class Rest {
|
|
|
107
107
|
code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
|
|
108
108
|
message: `${isTimeout ? "Timeout" : "Network error"} on ${method} ${endpoint}: ${message}`,
|
|
109
109
|
});
|
|
110
|
+
// Emit so the node manager can react (e.g. trigger reconnection logic)
|
|
110
111
|
this.manager.emit(Enums_1.ManagerEventTypes.NodeError, this.node, error);
|
|
111
112
|
return null;
|
|
112
113
|
}
|
|
@@ -114,9 +115,16 @@ class Rest {
|
|
|
114
115
|
if (status >= 200 && status < 300) {
|
|
115
116
|
return data;
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
if (status === 404) {
|
|
119
|
+
if (data?.message === "Guild not found") {
|
|
120
|
+
// Lavalink sometimes returns "Guild not found" for inactive players
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
if (data?.message === "Session not found") {
|
|
124
|
+
// Session expired — trigger reconnection instead of crashing
|
|
125
|
+
this.manager.emit(Enums_1.ManagerEventTypes.NodeError, this.node, new MagmastreamError_1.MagmaStreamError({ code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED, message: "Session not found" }));
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
120
128
|
}
|
|
121
129
|
const message = typeof data === "string"
|
|
122
130
|
? data
|
|
@@ -10,6 +10,7 @@ import { AutoPlayPlatform, LoadTypes, ManagerEventTypes, PlayerStateEventTypes,
|
|
|
10
10
|
import { Node } from "./Node";
|
|
11
11
|
import { Player } from "./Player";
|
|
12
12
|
import { Plugin } from "./Plugin";
|
|
13
|
+
import { RedisOptions } from "ioredis";
|
|
13
14
|
/**
|
|
14
15
|
* Manager Options
|
|
15
16
|
*/
|
|
@@ -242,11 +243,7 @@ export interface VoiceServerUpdate {
|
|
|
242
243
|
/**
|
|
243
244
|
* Redis Configuration
|
|
244
245
|
*/
|
|
245
|
-
export interface RedisConfig {
|
|
246
|
-
host: string;
|
|
247
|
-
port: number;
|
|
248
|
-
password?: string;
|
|
249
|
-
db?: number;
|
|
246
|
+
export interface RedisConfig extends RedisOptions {
|
|
250
247
|
prefix?: string;
|
|
251
248
|
}
|
|
252
249
|
/**
|
package/dist/structures/Utils.js
CHANGED
|
@@ -788,9 +788,7 @@ class PlayerUtils {
|
|
|
788
788
|
* Gets the Redis key for player storage.
|
|
789
789
|
*/
|
|
790
790
|
static getRedisKey() {
|
|
791
|
-
|
|
792
|
-
// Default prefix
|
|
793
|
-
let prefix = (cfg.prefix ?? "magmastream:").trim();
|
|
791
|
+
let prefix = (this.manager.options.stateStorage.redisConfig.prefix ?? "magmastream:").trim();
|
|
794
792
|
prefix = prefix.replace(/:+$/g, "") + ":";
|
|
795
793
|
return prefix;
|
|
796
794
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magmastream",
|
|
3
|
-
"version": "2.10.2-alpha.
|
|
3
|
+
"version": "2.10.2-alpha.5",
|
|
4
4
|
"description": "A user-friendly Lavalink client designed for NodeJS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"@favware/rollup-type-bundler": "^4.0.0",
|
|
24
24
|
"@types/jsdom": "^28.0.0",
|
|
25
25
|
"@types/lodash": "^4.17.24",
|
|
26
|
-
"@types/node": "^25.3.
|
|
26
|
+
"@types/node": "^25.3.5",
|
|
27
27
|
"@types/ws": "^8.18.1",
|
|
28
|
-
"@typescript-eslint/eslint-plugin": "^8.56.
|
|
29
|
-
"@typescript-eslint/parser": "^8.56.
|
|
30
|
-
"eslint": "^10.0.
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
29
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
30
|
+
"eslint": "^10.0.3",
|
|
31
31
|
"npm-run-all": "^4.1.5",
|
|
32
32
|
"prettier": "^3.8.1",
|
|
33
33
|
"typedoc": "^0.28.17",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"discord.js": "14.x",
|
|
51
51
|
"discordeno": "21.x",
|
|
52
52
|
"eris": "0.18.x",
|
|
53
|
-
"oceanic.js": "1.
|
|
53
|
+
"oceanic.js": "1.14.x",
|
|
54
54
|
"seyfert": "4.x"
|
|
55
55
|
},
|
|
56
56
|
"overrides": {
|