magmastream 2.10.2-dev.3 → 2.10.3-dev.0
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.
|
@@ -169,7 +169,6 @@ export declare class Manager extends EventEmitter {
|
|
|
169
169
|
* @param string - The string to escape.
|
|
170
170
|
* @returns The escaped string.
|
|
171
171
|
*/
|
|
172
|
-
private escapeRegExp;
|
|
173
172
|
/**
|
|
174
173
|
* Checks if the given data is a voice update.
|
|
175
174
|
* @param data The data to check.
|
|
@@ -16,6 +16,11 @@ const Enums_1 = require("./Enums");
|
|
|
16
16
|
const package_json_1 = require("../../package.json");
|
|
17
17
|
const MagmastreamError_1 = require("./MagmastreamError");
|
|
18
18
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
19
|
+
function escapeRegExp(value) {
|
|
20
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
+
}
|
|
22
|
+
const YOUTUBE_URL_PATTERN = /(youtube\.com|youtu\.be)/;
|
|
23
|
+
const BLOCKED_WORDS_PATTERN = new RegExp(`\\b(${blockedWords_1.blockedWords.map(escapeRegExp).join("|")})\\b`, "gi");
|
|
19
24
|
/**
|
|
20
25
|
* The main hub for interacting with Lavalink and using Magmastream.
|
|
21
26
|
*/
|
|
@@ -258,7 +263,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
258
263
|
}
|
|
259
264
|
if (this.options.normalizeYouTubeTitles && "tracks" in result) {
|
|
260
265
|
const processTrack = (track) => {
|
|
261
|
-
if (
|
|
266
|
+
if (!YOUTUBE_URL_PATTERN.test(track.uri))
|
|
262
267
|
return track;
|
|
263
268
|
const { cleanTitle, cleanAuthor } = this.parseYouTubeTitle(track.title, track.author);
|
|
264
269
|
track.title = cleanTitle;
|
|
@@ -267,7 +272,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
267
272
|
};
|
|
268
273
|
result.tracks = result.tracks.map(processTrack);
|
|
269
274
|
if ("playlist" in result && result.playlist) {
|
|
270
|
-
result.playlist.tracks = result.
|
|
275
|
+
result.playlist.tracks = result.tracks;
|
|
271
276
|
}
|
|
272
277
|
}
|
|
273
278
|
const summary = "tracks" in result ? result.tracks.map((t) => Object.fromEntries(Object.entries(t).filter(([key]) => key !== "requester"))) : [];
|
|
@@ -780,9 +785,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
780
785
|
const cleanAuthor = originalAuthor.replace("- Topic", "").trim();
|
|
781
786
|
title = title.replace("Topic -", "").trim();
|
|
782
787
|
// Remove blocked words and phrases
|
|
783
|
-
|
|
784
|
-
const blockedWordsPattern = new RegExp(`\\b(${escapedBlockedWords.join("|")})\\b`, "gi");
|
|
785
|
-
title = title.replace(blockedWordsPattern, "").trim();
|
|
788
|
+
title = title.replace(BLOCKED_WORDS_PATTERN, "").trim();
|
|
786
789
|
// Remove empty brackets and balance remaining brackets
|
|
787
790
|
title = title
|
|
788
791
|
.replace(/[([{]\s*[)\]}]/g, "") // Empty brackets
|
|
@@ -847,10 +850,6 @@ class Manager extends events_1.EventEmitter {
|
|
|
847
850
|
* @param string - The string to escape.
|
|
848
851
|
* @returns The escaped string.
|
|
849
852
|
*/
|
|
850
|
-
escapeRegExp(string) {
|
|
851
|
-
// Replace special regex characters with their escaped counterparts
|
|
852
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
853
|
-
}
|
|
854
853
|
/**
|
|
855
854
|
* Checks if the given data is a voice update.
|
|
856
855
|
* @param data The data to check.
|
package/dist/structures/Node.js
CHANGED
|
@@ -295,8 +295,6 @@ class Node {
|
|
|
295
295
|
* @returns {Promise<void>} A promise that resolves when the node and its resources have been destroyed.
|
|
296
296
|
*/
|
|
297
297
|
async destroy() {
|
|
298
|
-
if (!this.connected)
|
|
299
|
-
return;
|
|
300
298
|
const debugInfo = {
|
|
301
299
|
connected: this.connected,
|
|
302
300
|
identifier: this.options.identifier,
|
|
@@ -310,10 +308,16 @@ class Node {
|
|
|
310
308
|
if (players.size) {
|
|
311
309
|
await Promise.all(Array.from(players.values(), (player) => player.autoMoveNode()));
|
|
312
310
|
}
|
|
313
|
-
|
|
314
|
-
this.socket.removeAllListeners();
|
|
315
|
-
this.reconnectAttempts = 1;
|
|
311
|
+
// Always clear reconnect state regardless of connection status
|
|
316
312
|
clearTimeout(this.reconnectTimeout);
|
|
313
|
+
this.reconnectTimeout = undefined;
|
|
314
|
+
this.reconnectAttempts = 1;
|
|
315
|
+
// Only close the socket if it is actually open
|
|
316
|
+
if (this.connected) {
|
|
317
|
+
this.socket.close(1000, "destroy");
|
|
318
|
+
this.socket.removeAllListeners();
|
|
319
|
+
}
|
|
320
|
+
this.socket = null;
|
|
317
321
|
this.manager.emit(Enums_1.ManagerEventTypes.NodeDestroy, this);
|
|
318
322
|
this.manager.nodes.delete(this.options.identifier);
|
|
319
323
|
}
|
|
@@ -1125,7 +1129,7 @@ class Node {
|
|
|
1125
1129
|
});
|
|
1126
1130
|
}
|
|
1127
1131
|
try {
|
|
1128
|
-
await this.rest.put(`/v4/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`,
|
|
1132
|
+
await this.rest.put(`/v4/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, segments.map((v) => v.toLowerCase()));
|
|
1129
1133
|
}
|
|
1130
1134
|
catch (err) {
|
|
1131
1135
|
throw err instanceof MagmastreamError_1.MagmaStreamError
|
|
@@ -943,7 +943,12 @@ class Player {
|
|
|
943
943
|
context: { guildId: this.guildId },
|
|
944
944
|
});
|
|
945
945
|
}
|
|
946
|
-
|
|
946
|
+
// Only destroy the player on the old node if it is still reachable.
|
|
947
|
+
// If the server is down the REST call would fail anyway; skipping it
|
|
948
|
+
// also prevents a spurious error when switching nodes during an outage.
|
|
949
|
+
if (this.node.connected) {
|
|
950
|
+
await this.node.rest.destroyPlayer(this.guildId).catch(() => { });
|
|
951
|
+
}
|
|
947
952
|
this.manager.players.delete(this.guildId);
|
|
948
953
|
this.node = node;
|
|
949
954
|
this.manager.players.set(this.guildId, this);
|
package/dist/structures/Rest.js
CHANGED
|
@@ -104,8 +104,6 @@ class Rest {
|
|
|
104
104
|
*/
|
|
105
105
|
async request(method, endpoint, body) {
|
|
106
106
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REST] ${method} request to ${endpoint} with body: ${Utils_1.JSONUtils.safe(body, 2)}`);
|
|
107
|
-
const controller = new AbortController();
|
|
108
|
-
const timeoutHandle = setTimeout(() => controller.abort(), this.node.options.apiRequestTimeoutMs);
|
|
109
107
|
let response = null;
|
|
110
108
|
try {
|
|
111
109
|
response = await (0, undici_1.fetch)(this.url + endpoint, {
|
|
@@ -115,11 +113,11 @@ class Rest {
|
|
|
115
113
|
Authorization: this.password,
|
|
116
114
|
},
|
|
117
115
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
118
|
-
signal:
|
|
116
|
+
signal: AbortSignal.timeout(this.node.options.apiRequestTimeoutMs),
|
|
119
117
|
});
|
|
120
118
|
}
|
|
121
119
|
catch (e) {
|
|
122
|
-
const isTimeout = e instanceof Error && e.name === "AbortError";
|
|
120
|
+
const isTimeout = e instanceof Error && (e.name === "AbortError" || e.name === "TimeoutError");
|
|
123
121
|
const message = e instanceof Error ? e.message : "Unknown error";
|
|
124
122
|
const error = new MagmastreamError_1.MagmaStreamError({
|
|
125
123
|
code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
|
|
@@ -128,9 +126,6 @@ class Rest {
|
|
|
128
126
|
this.manager.emit(Enums_1.ManagerEventTypes.NodeError, this.node, error);
|
|
129
127
|
return null;
|
|
130
128
|
}
|
|
131
|
-
finally {
|
|
132
|
-
clearTimeout(timeoutHandle);
|
|
133
|
-
}
|
|
134
129
|
const { status } = response;
|
|
135
130
|
const data = status !== 204 ? await response.json() : null;
|
|
136
131
|
if (status >= 200 && status < 300) {
|
|
@@ -15,7 +15,7 @@ class DiscordJSManager extends Manager_1.Manager {
|
|
|
15
15
|
constructor(client, options) {
|
|
16
16
|
super(options, true);
|
|
17
17
|
this.client = client;
|
|
18
|
-
const { version: djsVersion } = moduleRequire("discord.js
|
|
18
|
+
const { version: djsVersion } = moduleRequire("discord.js");
|
|
19
19
|
const [major, minor] = djsVersion.split(".").map(Number);
|
|
20
20
|
if (!this.client.options.intents.has(GUILD_VOICE_STATES_INTENT)) {
|
|
21
21
|
throw new MagmastreamError_1.MagmaStreamError({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magmastream",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.3-dev.0",
|
|
4
4
|
"description": "A user-friendly Lavalink client designed for NodeJS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"lint": "eslint \"src/**/*.{ts,js}\"",
|
|
17
17
|
"lint:fix": "eslint --fix \"src/**/*.{ts,js}\"",
|
|
18
18
|
"ci": "run-s format:check lint build types",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"version:alpha": "node scripts/prerelease-version.cjs alpha",
|
|
20
|
+
"version:dev": "node scripts/prerelease-version.cjs dev",
|
|
21
|
+
"release:alpha": "npm run format && npm run lint:fix && npm run ci && npm run version:alpha && npm publish --tag alpha && git push && git push --follow-tags",
|
|
22
|
+
"release:dev": "npm run format && npm run lint:fix && npm run ci && npm run version:dev && npm publish --tag dev && git push && git push --follow-tags"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
25
|
"@favware/rollup-type-bundler": "^4.0.0",
|