lavalink-client 2.7.4 → 2.7.6
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/dist/index.d.mts +120 -27
- package/dist/index.d.ts +120 -27
- package/dist/index.js +557 -559
- package/dist/index.mjs +557 -559
- package/package.json +78 -78
package/dist/index.js
CHANGED
|
@@ -105,6 +105,9 @@ var DebugEvents = /* @__PURE__ */ ((DebugEvents2) => {
|
|
|
105
105
|
DebugEvents2["FailedToConnectToNodes"] = "FailedToConnectToNodes";
|
|
106
106
|
DebugEvents2["NoAudioDebug"] = "NoAudioDebug";
|
|
107
107
|
DebugEvents2["PlayerAutoReconnect"] = "PlayerAutoReconnect";
|
|
108
|
+
DebugEvents2["PlayerDestroyFail"] = "PlayerDestroyFail";
|
|
109
|
+
DebugEvents2["PlayerChangeNodeFailNoEligibleNode"] = "PlayerChangeNodeFailNoEligibleNode";
|
|
110
|
+
DebugEvents2["PlayerChangeNodeFail"] = "PlayerChangeNodeFail";
|
|
108
111
|
return DebugEvents2;
|
|
109
112
|
})(DebugEvents || {});
|
|
110
113
|
var DestroyReasons = /* @__PURE__ */ ((DestroyReasons2) => {
|
|
@@ -748,7 +751,7 @@ var ManagerUtils = class {
|
|
|
748
751
|
}
|
|
749
752
|
validateQueryString(node, queryString, sourceString) {
|
|
750
753
|
if (!node.info) throw new Error("No Lavalink Node was provided");
|
|
751
|
-
if (!node.info.sourceManagers?.length) throw new Error("Lavalink Node, has no sourceManagers enabled");
|
|
754
|
+
if (this.LavalinkManager.options?.autoChecks?.sourcesValidations && !node.info.sourceManagers?.length) throw new Error("Lavalink Node, has no sourceManagers enabled");
|
|
752
755
|
if (!queryString.trim().length) throw new Error(`Query string is empty, please provide a valid query string.`);
|
|
753
756
|
if (sourceString === "speak" && queryString.length > 100) throw new Error(`Query is speak, which is limited to 100 characters.`);
|
|
754
757
|
if (this.LavalinkManager.options?.linksBlacklist?.length > 0) {
|
|
@@ -777,6 +780,7 @@ var ManagerUtils = class {
|
|
|
777
780
|
throw new Error(`Query string contains a link / word which isn't whitelisted.`);
|
|
778
781
|
}
|
|
779
782
|
}
|
|
783
|
+
if (!this.LavalinkManager.options?.autoChecks?.sourcesValidations) return;
|
|
780
784
|
if ((SourceLinksRegexes.YoutubeMusicRegex.test(queryString) || SourceLinksRegexes.YoutubeRegex.test(queryString)) && !node.info?.sourceManagers?.includes("youtube")) {
|
|
781
785
|
throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'youtube' enabled");
|
|
782
786
|
}
|
|
@@ -860,6 +864,7 @@ var ManagerUtils = class {
|
|
|
860
864
|
const source = DefaultSources[sourceString.toLowerCase().trim()];
|
|
861
865
|
if (!source) throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
|
|
862
866
|
if (!node.info) throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
|
|
867
|
+
if (!this.LavalinkManager.options?.autoChecks?.sourcesValidations) return;
|
|
863
868
|
if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
|
|
864
869
|
throw new Error("Lavalink Node has not 'applemusic' enabled, which is required to have 'amsearch' work");
|
|
865
870
|
}
|
|
@@ -881,7 +886,7 @@ var ManagerUtils = class {
|
|
|
881
886
|
if (source === "scsearch" && !node.info?.sourceManagers?.includes("soundcloud")) {
|
|
882
887
|
throw new Error("Lavalink Node has not 'soundcloud' enabled, which is required to have 'scsearch' work");
|
|
883
888
|
}
|
|
884
|
-
if (source === "speak" && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
|
|
889
|
+
if (source === "speak" && this.LavalinkManager.options?.autoChecks?.pluginValidations && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
|
|
885
890
|
throw new Error("Lavalink Node has not 'speak' enabled, which is required to have 'speak' work");
|
|
886
891
|
}
|
|
887
892
|
if (source === "tdsearch" && !node.info?.sourceManagers?.includes("tidal")) {
|
|
@@ -890,7 +895,7 @@ var ManagerUtils = class {
|
|
|
890
895
|
if (source === "tdrec" && !node.info?.sourceManagers?.includes("tidal")) {
|
|
891
896
|
throw new Error("Lavalink Node has not 'tidal' enabled, which is required to have 'tdrec' work");
|
|
892
897
|
}
|
|
893
|
-
if (source === "tts" && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
|
|
898
|
+
if (source === "tts" && this.LavalinkManager.options?.autoChecks?.pluginValidations && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
|
|
894
899
|
throw new Error("Lavalink Node has not 'tts' enabled, which is required to have 'tts' work");
|
|
895
900
|
}
|
|
896
901
|
if (source === "ftts" && !(node.info?.sourceManagers?.includes("ftts") || node.info?.sourceManagers?.includes("flowery-tts") || node.info?.sourceManagers?.includes("flowerytts"))) {
|
|
@@ -899,7 +904,7 @@ var ManagerUtils = class {
|
|
|
899
904
|
if (source === "ymsearch" && !node.info?.sourceManagers?.includes("yandexmusic")) {
|
|
900
905
|
throw new Error("Lavalink Node has not 'yandexmusic' enabled, which is required to have 'ymsearch' work");
|
|
901
906
|
}
|
|
902
|
-
if (source === "ytmsearch" && !node.info
|
|
907
|
+
if (source === "ytmsearch" && !node.info?.sourceManagers?.includes("youtube")) {
|
|
903
908
|
throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytmsearch' work");
|
|
904
909
|
}
|
|
905
910
|
if (source === "ytsearch" && !node.info?.sourceManagers?.includes("youtube")) {
|
|
@@ -1042,9 +1047,6 @@ function safeStringify(obj, padding = 0) {
|
|
|
1042
1047
|
var LavalinkNode = class {
|
|
1043
1048
|
heartBeatPingTimestamp = 0;
|
|
1044
1049
|
heartBeatPongTimestamp = 0;
|
|
1045
|
-
get heartBeatPing() {
|
|
1046
|
-
return this.heartBeatPongTimestamp - this.heartBeatPingTimestamp;
|
|
1047
|
-
}
|
|
1048
1050
|
heartBeatInterval;
|
|
1049
1051
|
pingTimeout;
|
|
1050
1052
|
isAlive = false;
|
|
@@ -1068,6 +1070,17 @@ var LavalinkNode = class {
|
|
|
1068
1070
|
used: 0
|
|
1069
1071
|
},
|
|
1070
1072
|
uptime: 0,
|
|
1073
|
+
/** something from nodeLink https://nodelink.js.org/docs/differences#detailed-statistics */
|
|
1074
|
+
detailedStats: {
|
|
1075
|
+
api: {
|
|
1076
|
+
requests: {},
|
|
1077
|
+
errors: {}
|
|
1078
|
+
},
|
|
1079
|
+
sources: {},
|
|
1080
|
+
playback: {
|
|
1081
|
+
events: {}
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1071
1084
|
frameStats: {
|
|
1072
1085
|
deficit: 0,
|
|
1073
1086
|
nulled: 0,
|
|
@@ -1092,6 +1105,68 @@ var LavalinkNode = class {
|
|
|
1092
1105
|
socket = null;
|
|
1093
1106
|
/** Version of what the Lavalink Server should be */
|
|
1094
1107
|
version = "v4";
|
|
1108
|
+
/**
|
|
1109
|
+
* Returns the LavalinkManager of the Node
|
|
1110
|
+
*/
|
|
1111
|
+
get _LManager() {
|
|
1112
|
+
return this.NodeManager.LavalinkManager;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Returns the Heartbeat Ping of the Node
|
|
1116
|
+
*/
|
|
1117
|
+
get heartBeatPing() {
|
|
1118
|
+
return this.heartBeatPongTimestamp - this.heartBeatPingTimestamp;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Returns wether the plugin validations are enabled or not
|
|
1122
|
+
*/
|
|
1123
|
+
get _checkForPlugins() {
|
|
1124
|
+
return !!this._LManager.options?.autoChecks?.pluginValidations;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Returns wether the source validations are enabled or not
|
|
1128
|
+
*/
|
|
1129
|
+
get _checkForSources() {
|
|
1130
|
+
return !!this._LManager.options?.autoChecks?.sourcesValidations;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Emits a debug event to the LavalinkManager
|
|
1134
|
+
* @param name name of the event
|
|
1135
|
+
* @param eventData event data
|
|
1136
|
+
*/
|
|
1137
|
+
_emitDebugEvent(name, eventData) {
|
|
1138
|
+
if (!this._LManager.options?.advancedOptions?.enableDebugEvents) return;
|
|
1139
|
+
this._LManager.emit("debug", name, eventData);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Returns if connected to the Node.
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```ts
|
|
1146
|
+
* const isConnected = player.node.connected;
|
|
1147
|
+
* console.log("node is connected: ", isConnected ? "yes" : "no")
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
get connected() {
|
|
1151
|
+
return this.socket && this.socket.readyState === import_ws.default.OPEN;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Returns the current ConnectionStatus
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```ts
|
|
1158
|
+
* try {
|
|
1159
|
+
* const statusOfConnection = player.node.connectionStatus;
|
|
1160
|
+
* console.log("node's connection status is:", statusOfConnection)
|
|
1161
|
+
* } catch (error) {
|
|
1162
|
+
* console.error("no socket available?", error)
|
|
1163
|
+
* }
|
|
1164
|
+
* ```
|
|
1165
|
+
*/
|
|
1166
|
+
get connectionStatus() {
|
|
1167
|
+
if (!this.socket) throw new Error("no websocket was initialized yet");
|
|
1168
|
+
return ["CONNECTING", "OPEN", "CLOSING", "CLOSED"][this.socket.readyState] || "UNKNOWN";
|
|
1169
|
+
}
|
|
1095
1170
|
/**
|
|
1096
1171
|
* Create a new Node
|
|
1097
1172
|
* @param options Lavalink Node Options
|
|
@@ -1181,10 +1256,10 @@ var LavalinkNode = class {
|
|
|
1181
1256
|
* ```
|
|
1182
1257
|
*/
|
|
1183
1258
|
async search(query, requestUser, throwOnEmpty = false) {
|
|
1184
|
-
const Query = this.
|
|
1185
|
-
this.
|
|
1186
|
-
if (Query.source) this.
|
|
1187
|
-
if (["bcsearch", "bandcamp"].includes(Query.source) && !this.info.sourceManagers.includes("bandcamp")) {
|
|
1259
|
+
const Query = this._LManager.utils.transformQuery(query);
|
|
1260
|
+
this._LManager.utils.validateQueryString(this, Query.query, Query.source);
|
|
1261
|
+
if (Query.source) this._LManager.utils.validateSourceString(this, Query.source);
|
|
1262
|
+
if (["bcsearch", "bandcamp"].includes(Query.source) && this._LManager.options?.autoChecks?.sourcesValidations && !this.info.sourceManagers.includes("bandcamp")) {
|
|
1188
1263
|
throw new Error("Bandcamp Search only works on the player (lavaplayer version < 2.2.0!");
|
|
1189
1264
|
}
|
|
1190
1265
|
const requestUrl = new URL(`${this.restAddress}/loadtracks`);
|
|
@@ -1203,13 +1278,11 @@ var LavalinkNode = class {
|
|
|
1203
1278
|
});
|
|
1204
1279
|
const resTracks = res.loadType === "playlist" ? res.data?.tracks : res.loadType === "track" ? [res.data] : res.loadType === "search" ? Array.isArray(res.data) ? res.data : [res.data] : [];
|
|
1205
1280
|
if (throwOnEmpty === true && (res.loadType === "empty" || !resTracks.length)) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1281
|
+
this._emitDebugEvent("SearchNothingFound" /* SearchNothingFound */, {
|
|
1282
|
+
state: "warn",
|
|
1283
|
+
message: `Search found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
|
|
1284
|
+
functionLayer: "(LavalinkNode > node | player) > search()"
|
|
1285
|
+
});
|
|
1213
1286
|
throw new Error("Nothing found");
|
|
1214
1287
|
}
|
|
1215
1288
|
return {
|
|
@@ -1222,10 +1295,10 @@ var LavalinkNode = class {
|
|
|
1222
1295
|
author: res.data.info?.author || res.data.pluginInfo?.author || null,
|
|
1223
1296
|
thumbnail: res.data.info?.artworkUrl || res.data.pluginInfo?.artworkUrl || (typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1 ? null : resTracks[res.data?.info?.selectedTrack] ? resTracks[res.data?.info?.selectedTrack]?.info?.artworkUrl || resTracks[res.data?.info?.selectedTrack]?.info?.pluginInfo?.artworkUrl : null) || null,
|
|
1224
1297
|
uri: res.data.info?.url || res.data.info?.uri || res.data.info?.link || res.data.pluginInfo?.url || res.data.pluginInfo?.uri || res.data.pluginInfo?.link || null,
|
|
1225
|
-
selectedTrack: typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1 ? null : resTracks[res.data?.info?.selectedTrack] ? this.
|
|
1298
|
+
selectedTrack: typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1 ? null : resTracks[res.data?.info?.selectedTrack] ? this._LManager.utils.buildTrack(resTracks[res.data?.info?.selectedTrack], requestUser) : null,
|
|
1226
1299
|
duration: resTracks.length ? resTracks.reduce((acc, cur) => acc + (cur?.info?.duration || cur?.info?.length || 0), 0) : 0
|
|
1227
1300
|
} : null,
|
|
1228
|
-
tracks: resTracks.length ? resTracks.map((t) => this.
|
|
1301
|
+
tracks: resTracks.length ? resTracks.map((t) => this._LManager.utils.buildTrack(t, requestUser)) : []
|
|
1229
1302
|
};
|
|
1230
1303
|
}
|
|
1231
1304
|
/**
|
|
@@ -1242,29 +1315,27 @@ var LavalinkNode = class {
|
|
|
1242
1315
|
* ```
|
|
1243
1316
|
*/
|
|
1244
1317
|
async lavaSearch(query, requestUser, throwOnEmpty = false) {
|
|
1245
|
-
const Query = this.
|
|
1246
|
-
if (Query.source) this.
|
|
1318
|
+
const Query = this._LManager.utils.transformLavaSearchQuery(query);
|
|
1319
|
+
if (Query.source) this._LManager.utils.validateSourceString(this, Query.source);
|
|
1247
1320
|
if (/^https?:\/\//.test(Query.query)) return this.search({ query: Query.query, source: Query.source }, requestUser);
|
|
1248
1321
|
if (!["spsearch", "sprec", "amsearch", "dzsearch", "dzisrc", "ytmsearch", "ytsearch"].includes(Query.source)) throw new SyntaxError(`Query.source must be a source from LavaSrc: "spsearch" | "sprec" | "amsearch" | "dzsearch" | "dzisrc" | "ytmsearch" | "ytsearch"`);
|
|
1249
|
-
if (!this.info
|
|
1250
|
-
if (!this.info
|
|
1322
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavasearch-plugin")) throw new RangeError(`there is no lavasearch-plugin available in the lavalink node: ${this.id}`);
|
|
1323
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavasrc-plugin")) throw new RangeError(`there is no lavasrc-plugin available in the lavalink node: ${this.id}`);
|
|
1251
1324
|
const { response } = await this.rawRequest(`/loadsearch?query=${Query.source ? `${Query.source}:` : ""}${encodeURIComponent(Query.query)}${Query.types?.length ? `&types=${Query.types.join(",")}` : ""}`);
|
|
1252
1325
|
const res = response.status === 204 ? {} : await response.json();
|
|
1253
1326
|
if (throwOnEmpty === true && !Object.entries(res).flat().filter(Boolean).length) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
});
|
|
1260
|
-
}
|
|
1327
|
+
this._emitDebugEvent("LavaSearchNothingFound" /* LavaSearchNothingFound */, {
|
|
1328
|
+
state: "warn",
|
|
1329
|
+
message: `LavaSearch found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
|
|
1330
|
+
functionLayer: "(LavalinkNode > node | player) > lavaSearch()"
|
|
1331
|
+
});
|
|
1261
1332
|
throw new Error("Nothing found");
|
|
1262
1333
|
}
|
|
1263
1334
|
return {
|
|
1264
|
-
tracks: res.tracks?.map((v) => this.
|
|
1265
|
-
albums: res.albums?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.
|
|
1266
|
-
artists: res.artists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.
|
|
1267
|
-
playlists: res.playlists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.
|
|
1335
|
+
tracks: res.tracks?.map((v) => this._LManager.utils.buildTrack(v, requestUser)) || [],
|
|
1336
|
+
albums: res.albums?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
|
|
1337
|
+
artists: res.artists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
|
|
1338
|
+
playlists: res.playlists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
|
|
1268
1339
|
texts: res.texts?.map((v) => ({ text: v.text, pluginInfo: v?.plugin || v.pluginInfo })) || [],
|
|
1269
1340
|
pluginInfo: res.pluginInfo || res?.plugin
|
|
1270
1341
|
};
|
|
@@ -1293,13 +1364,11 @@ var LavalinkNode = class {
|
|
|
1293
1364
|
r.path = url.pathname + url.search;
|
|
1294
1365
|
}
|
|
1295
1366
|
});
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1367
|
+
this._emitDebugEvent("PlayerUpdateSuccess" /* PlayerUpdateSuccess */, {
|
|
1368
|
+
state: "log",
|
|
1369
|
+
message: `Player get's updated with following payload :: ${safeStringify(data.playerOptions, 3)}`,
|
|
1370
|
+
functionLayer: "LavalinkNode > node > updatePlayer()"
|
|
1371
|
+
});
|
|
1303
1372
|
this.syncPlayerData({}, res);
|
|
1304
1373
|
return res;
|
|
1305
1374
|
}
|
|
@@ -1335,19 +1404,17 @@ var LavalinkNode = class {
|
|
|
1335
1404
|
*/
|
|
1336
1405
|
connect(sessionId) {
|
|
1337
1406
|
if (this.connected) {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1407
|
+
this._emitDebugEvent("TryingConnectWhileConnected" /* TryingConnectWhileConnected */, {
|
|
1408
|
+
state: "warn",
|
|
1409
|
+
message: `Tryed to connect to node, but it's already connected!`,
|
|
1410
|
+
functionLayer: "LavalinkNode > node > connect()"
|
|
1411
|
+
});
|
|
1345
1412
|
return;
|
|
1346
1413
|
}
|
|
1347
1414
|
const headers = {
|
|
1348
1415
|
Authorization: this.options.authorization,
|
|
1349
|
-
"User-Id": this.
|
|
1350
|
-
"Client-Name": this.
|
|
1416
|
+
"User-Id": this._LManager.options.client.id,
|
|
1417
|
+
"Client-Name": this._LManager.options.client.username || "Lavalink-Client"
|
|
1351
1418
|
};
|
|
1352
1419
|
if (typeof this.options.sessionId === "string" || typeof sessionId === "string") {
|
|
1353
1420
|
headers["Session-Id"] = this.options.sessionId || sessionId;
|
|
@@ -1360,34 +1427,27 @@ var LavalinkNode = class {
|
|
|
1360
1427
|
this.socket.on("error", this.error.bind(this));
|
|
1361
1428
|
}
|
|
1362
1429
|
heartBeat() {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
});
|
|
1369
|
-
}
|
|
1430
|
+
this._emitDebugEvent("HeartBeatTriggered" /* HeartBeatTriggered */, {
|
|
1431
|
+
state: "log",
|
|
1432
|
+
message: `Node Socket Heartbeat triggered, resetting old Timeout to 65000ms (should happen every 60s due to /stats event)`,
|
|
1433
|
+
functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat()"
|
|
1434
|
+
});
|
|
1370
1435
|
this.resetAckTimeouts(false, true);
|
|
1371
1436
|
if (this.pingTimeout) clearTimeout(this.pingTimeout);
|
|
1372
1437
|
this.pingTimeout = setTimeout(() => {
|
|
1373
1438
|
this.pingTimeout = null;
|
|
1374
1439
|
if (!this.socket) {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
message: `Heartbeat registered a disconnect, but socket didn't exist therefore can't terminate`,
|
|
1379
|
-
functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1382
|
-
return;
|
|
1383
|
-
}
|
|
1384
|
-
if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
|
|
1385
|
-
this.NodeManager.LavalinkManager.emit("debug", "SocketTerminateHeartBeatTimeout" /* SocketTerminateHeartBeatTimeout */, {
|
|
1386
|
-
state: "warn",
|
|
1387
|
-
message: `Heartbeat registered a disconnect, because timeout wasn't resetted in time. Terminating Web-Socket`,
|
|
1440
|
+
return this._emitDebugEvent("NoSocketOnDestroy" /* NoSocketOnDestroy */, {
|
|
1441
|
+
state: "error",
|
|
1442
|
+
message: `Heartbeat registered a disconnect, but socket didn't exist therefore can't terminate`,
|
|
1388
1443
|
functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
|
|
1389
1444
|
});
|
|
1390
1445
|
}
|
|
1446
|
+
this._emitDebugEvent("SocketTerminateHeartBeatTimeout" /* SocketTerminateHeartBeatTimeout */, {
|
|
1447
|
+
state: "warn",
|
|
1448
|
+
message: `Heartbeat registered a disconnect, because timeout wasn't resetted in time. Terminating Web-Socket`,
|
|
1449
|
+
functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
|
|
1450
|
+
});
|
|
1391
1451
|
this.isAlive = false;
|
|
1392
1452
|
this.socket.terminate();
|
|
1393
1453
|
}, 65e3);
|
|
@@ -1423,71 +1483,75 @@ var LavalinkNode = class {
|
|
|
1423
1483
|
*/
|
|
1424
1484
|
destroy(destroyReason, deleteNode = true, movePlayers = false) {
|
|
1425
1485
|
this.reconnectionState = "IDLE" /* IDLE */;
|
|
1426
|
-
const players = this.
|
|
1427
|
-
if (players
|
|
1428
|
-
const enableDebugEvents = this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents;
|
|
1429
|
-
const handlePlayerOperations = () => {
|
|
1430
|
-
if (movePlayers) {
|
|
1431
|
-
const nodeToMove = Array.from(this.NodeManager.leastUsedNodes("playingPlayers")).find((n) => n.connected && n.options.id !== this.id);
|
|
1432
|
-
if (nodeToMove) {
|
|
1433
|
-
return Promise.allSettled(Array.from(players.values()).map(
|
|
1434
|
-
(player) => player.changeNode(nodeToMove.options.id).catch((error) => {
|
|
1435
|
-
if (enableDebugEvents) {
|
|
1436
|
-
console.error(`Node > destroy() Failed to move player ${player.guildId}: ${error.message}`);
|
|
1437
|
-
}
|
|
1438
|
-
return player.destroy(error.message ?? "PlayerChangeNodeFail" /* PlayerChangeNodeFail */).catch((destroyError) => {
|
|
1439
|
-
if (enableDebugEvents) {
|
|
1440
|
-
console.error(`Node > destroy() Failed to destroy player ${player.guildId} after move failure: ${destroyError.message}`);
|
|
1441
|
-
}
|
|
1442
|
-
});
|
|
1443
|
-
})
|
|
1444
|
-
));
|
|
1445
|
-
} else {
|
|
1446
|
-
return Promise.allSettled(Array.from(players.values()).map(
|
|
1447
|
-
(player) => player.destroy("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */).catch((error) => {
|
|
1448
|
-
if (enableDebugEvents) {
|
|
1449
|
-
console.error(`Node > destroy() Failed to destroy player ${player.guildId}: ${error.message}`);
|
|
1450
|
-
}
|
|
1451
|
-
})
|
|
1452
|
-
));
|
|
1453
|
-
}
|
|
1454
|
-
} else {
|
|
1455
|
-
return Promise.allSettled(Array.from(players.values()).map(
|
|
1456
|
-
(player) => player.destroy(destroyReason || "NodeDestroy" /* NodeDestroy */).catch((error) => {
|
|
1457
|
-
if (enableDebugEvents) {
|
|
1458
|
-
console.error(`Node > destroy() Failed to destroy player ${player.guildId}: ${error.message}`);
|
|
1459
|
-
}
|
|
1460
|
-
})
|
|
1461
|
-
));
|
|
1462
|
-
}
|
|
1463
|
-
};
|
|
1464
|
-
handlePlayerOperations().finally(() => {
|
|
1465
|
-
this.socket?.close(1e3, "Node-Destroy");
|
|
1466
|
-
this.socket?.removeAllListeners();
|
|
1467
|
-
this.socket = null;
|
|
1468
|
-
this.resetReconnectionAttempts();
|
|
1469
|
-
if (deleteNode) {
|
|
1470
|
-
this.NodeManager.emit("destroy", this, destroyReason);
|
|
1471
|
-
this.NodeManager.nodes.delete(this.id);
|
|
1472
|
-
this.resetAckTimeouts(true, true);
|
|
1473
|
-
} else {
|
|
1474
|
-
this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
|
|
1475
|
-
}
|
|
1476
|
-
});
|
|
1477
|
-
} else {
|
|
1486
|
+
const players = this._LManager.players.filter((p) => p.node.id === this.id);
|
|
1487
|
+
if (!players?.size) {
|
|
1478
1488
|
this.socket?.close(1e3, "Node-Destroy");
|
|
1479
1489
|
this.socket?.removeAllListeners();
|
|
1480
1490
|
this.socket = null;
|
|
1481
1491
|
this.resetReconnectionAttempts();
|
|
1482
|
-
if (deleteNode) {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
}
|
|
1492
|
+
if (!deleteNode) return void this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
|
|
1493
|
+
;
|
|
1494
|
+
this.NodeManager.emit("destroy", this, destroyReason);
|
|
1495
|
+
this.NodeManager.nodes.delete(this.id);
|
|
1496
|
+
this.resetAckTimeouts(true, true);
|
|
1497
|
+
return;
|
|
1489
1498
|
}
|
|
1490
|
-
|
|
1499
|
+
const handlePlayerOperations = () => {
|
|
1500
|
+
if (!movePlayers) {
|
|
1501
|
+
return Promise.allSettled(Array.from(players.values()).map(
|
|
1502
|
+
(player) => player.destroy(destroyReason || "NodeDestroy" /* NodeDestroy */).catch((error) => {
|
|
1503
|
+
this._emitDebugEvent("PlayerDestroyFail" /* PlayerDestroyFail */, {
|
|
1504
|
+
state: "error",
|
|
1505
|
+
message: `Failed to destroy player ${player.guildId}: ${error.message}`,
|
|
1506
|
+
error,
|
|
1507
|
+
functionLayer: "Node > destroy() > movePlayers"
|
|
1508
|
+
});
|
|
1509
|
+
})
|
|
1510
|
+
));
|
|
1511
|
+
}
|
|
1512
|
+
const nodeToMove = Array.from(this.NodeManager.leastUsedNodes("playingPlayers")).find((n) => n.connected && n.options.id !== this.id);
|
|
1513
|
+
if (!nodeToMove) {
|
|
1514
|
+
return Promise.allSettled(Array.from(players.values()).map(
|
|
1515
|
+
(player) => player.destroy("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */).catch((error) => {
|
|
1516
|
+
this._emitDebugEvent("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */, {
|
|
1517
|
+
state: "error",
|
|
1518
|
+
message: `Failed to destroy player ${player.guildId}: ${error.message}`,
|
|
1519
|
+
error,
|
|
1520
|
+
functionLayer: "Node > destroy() > movePlayers"
|
|
1521
|
+
});
|
|
1522
|
+
})
|
|
1523
|
+
));
|
|
1524
|
+
}
|
|
1525
|
+
return Promise.allSettled(Array.from(players.values()).map(
|
|
1526
|
+
(player) => player.changeNode(nodeToMove.options.id).catch((error) => {
|
|
1527
|
+
this._emitDebugEvent("PlayerChangeNodeFail" /* PlayerChangeNodeFail */, {
|
|
1528
|
+
state: "error",
|
|
1529
|
+
message: `Failed to move player ${player.guildId}: ${error.message}`,
|
|
1530
|
+
error,
|
|
1531
|
+
functionLayer: "Node > destroy() > movePlayers"
|
|
1532
|
+
});
|
|
1533
|
+
return player.destroy(error.message ?? "PlayerChangeNodeFail" /* PlayerChangeNodeFail */).catch((destroyError) => {
|
|
1534
|
+
this._emitDebugEvent("PlayerDestroyFail" /* PlayerDestroyFail */, {
|
|
1535
|
+
state: "error",
|
|
1536
|
+
message: `Failed to destroy player ${player.guildId} after move failure: ${destroyError.message}`,
|
|
1537
|
+
error: destroyError,
|
|
1538
|
+
functionLayer: "Node > destroy() > movePlayers"
|
|
1539
|
+
});
|
|
1540
|
+
});
|
|
1541
|
+
})
|
|
1542
|
+
));
|
|
1543
|
+
};
|
|
1544
|
+
return void handlePlayerOperations().finally(() => {
|
|
1545
|
+
this.socket?.close(1e3, "Node-Destroy");
|
|
1546
|
+
this.socket?.removeAllListeners();
|
|
1547
|
+
this.socket = null;
|
|
1548
|
+
this.resetReconnectionAttempts();
|
|
1549
|
+
if (!deleteNode) return void this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
|
|
1550
|
+
this.NodeManager.emit("destroy", this, destroyReason);
|
|
1551
|
+
this.NodeManager.nodes.delete(this.id);
|
|
1552
|
+
this.resetAckTimeouts(true, true);
|
|
1553
|
+
return;
|
|
1554
|
+
});
|
|
1491
1555
|
}
|
|
1492
1556
|
/**
|
|
1493
1557
|
* Disconnects the Node-Connection (Websocket)
|
|
@@ -1510,35 +1574,6 @@ var LavalinkNode = class {
|
|
|
1510
1574
|
this.resetReconnectionAttempts();
|
|
1511
1575
|
this.NodeManager.emit("disconnect", this, { code: 1e3, reason: disconnectReason });
|
|
1512
1576
|
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Returns if connected to the Node.
|
|
1515
|
-
*
|
|
1516
|
-
* @example
|
|
1517
|
-
* ```ts
|
|
1518
|
-
* const isConnected = player.node.connected;
|
|
1519
|
-
* console.log("node is connected: ", isConnected ? "yes" : "no")
|
|
1520
|
-
* ```
|
|
1521
|
-
*/
|
|
1522
|
-
get connected() {
|
|
1523
|
-
return this.socket && this.socket.readyState === import_ws.default.OPEN;
|
|
1524
|
-
}
|
|
1525
|
-
/**
|
|
1526
|
-
* Returns the current ConnectionStatus
|
|
1527
|
-
*
|
|
1528
|
-
* @example
|
|
1529
|
-
* ```ts
|
|
1530
|
-
* try {
|
|
1531
|
-
* const statusOfConnection = player.node.connectionStatus;
|
|
1532
|
-
* console.log("node's connection status is:", statusOfConnection)
|
|
1533
|
-
* } catch (error) {
|
|
1534
|
-
* console.error("no socket available?", error)
|
|
1535
|
-
* }
|
|
1536
|
-
* ```
|
|
1537
|
-
*/
|
|
1538
|
-
get connectionStatus() {
|
|
1539
|
-
if (!this.socket) throw new Error("no websocket was initialized yet");
|
|
1540
|
-
return ["CONNECTING", "OPEN", "CLOSING", "CLOSED"][this.socket.readyState] || "UNKNOWN";
|
|
1541
|
-
}
|
|
1542
1577
|
/**
|
|
1543
1578
|
* Gets all Players of a Node
|
|
1544
1579
|
* @returns array of players inside of lavalink
|
|
@@ -1612,7 +1647,7 @@ var LavalinkNode = class {
|
|
|
1612
1647
|
*/
|
|
1613
1648
|
singleTrack: async (encoded, requester) => {
|
|
1614
1649
|
if (!encoded) throw new SyntaxError("No encoded (Base64 string) was provided");
|
|
1615
|
-
return this.
|
|
1650
|
+
return this._LManager.utils?.buildTrack(await this.request(`/decodetrack?encodedTrack=${encodeURIComponent(encoded.replace(/\s/g, ""))}`), requester);
|
|
1616
1651
|
},
|
|
1617
1652
|
/**
|
|
1618
1653
|
* Decodes multiple tracks into their info
|
|
@@ -1633,7 +1668,7 @@ var LavalinkNode = class {
|
|
|
1633
1668
|
r.method = "POST";
|
|
1634
1669
|
r.body = safeStringify(encodeds);
|
|
1635
1670
|
r.headers["Content-Type"] = "application/json";
|
|
1636
|
-
}).then((r) => r.map((track) => this.
|
|
1671
|
+
}).then((r) => r.map((track) => this._LManager.utils.buildTrack(track, requester)));
|
|
1637
1672
|
}
|
|
1638
1673
|
};
|
|
1639
1674
|
lyrics = {
|
|
@@ -1652,8 +1687,8 @@ var LavalinkNode = class {
|
|
|
1652
1687
|
*/
|
|
1653
1688
|
get: async (track, skipTrackSource = false) => {
|
|
1654
1689
|
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
|
|
1655
|
-
if (!this.info
|
|
1656
|
-
if (!this.info
|
|
1690
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavalyrics-plugin")) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1691
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavasrc-plugin") && this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "java-lyrics-plugin")) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1657
1692
|
const url = `/lyrics?track=${track.encoded}&skipTrackSource=${skipTrackSource}`;
|
|
1658
1693
|
return await this.request(url);
|
|
1659
1694
|
},
|
|
@@ -1672,8 +1707,8 @@ var LavalinkNode = class {
|
|
|
1672
1707
|
*/
|
|
1673
1708
|
getCurrent: async (guildId, skipTrackSource = false) => {
|
|
1674
1709
|
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
|
|
1675
|
-
if (!this.info
|
|
1676
|
-
if (!this.info
|
|
1710
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavalyrics-plugin")) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1711
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavasrc-plugin") && this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "java-lyrics-plugin")) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1677
1712
|
const url = `/sessions/${this.sessionId}/players/${guildId}/track/lyrics?skipTrackSource=${skipTrackSource}`;
|
|
1678
1713
|
return await this.request(url);
|
|
1679
1714
|
},
|
|
@@ -1691,7 +1726,7 @@ var LavalinkNode = class {
|
|
|
1691
1726
|
*/
|
|
1692
1727
|
subscribe: async (guildId) => {
|
|
1693
1728
|
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
|
|
1694
|
-
if (!this.info
|
|
1729
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavalyrics-plugin")) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1695
1730
|
return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/subscribe`, (options) => {
|
|
1696
1731
|
options.method = "POST";
|
|
1697
1732
|
});
|
|
@@ -1710,7 +1745,7 @@ var LavalinkNode = class {
|
|
|
1710
1745
|
*/
|
|
1711
1746
|
unsubscribe: async (guildId) => {
|
|
1712
1747
|
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
|
|
1713
|
-
if (!this.info
|
|
1748
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "lavalyrics-plugin")) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
|
|
1714
1749
|
return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/subscribe`, (options) => {
|
|
1715
1750
|
options.method = "DELETE";
|
|
1716
1751
|
});
|
|
@@ -1728,6 +1763,19 @@ var LavalinkNode = class {
|
|
|
1728
1763
|
async fetchStats() {
|
|
1729
1764
|
return await this.request(`/stats`);
|
|
1730
1765
|
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Request NodeLink connection metrics. https://nodelink.js.org/docs/differences#connection-metrics
|
|
1768
|
+
* @returns the connection metrics of the node
|
|
1769
|
+
*
|
|
1770
|
+
* @example
|
|
1771
|
+
* ```ts
|
|
1772
|
+
* const connectionMetrics = await player.node.fetchConnectionMetrics();
|
|
1773
|
+
* ```
|
|
1774
|
+
*/
|
|
1775
|
+
async fetchConnectionMetrics() {
|
|
1776
|
+
if (this.info && !this.info.isNodelink) throw new Error("There is no Information about wether you are using NodeLink instead of Lavalink, so this function won't work");
|
|
1777
|
+
return await this.request(`/connection`);
|
|
1778
|
+
}
|
|
1731
1779
|
/**
|
|
1732
1780
|
* Request Lavalink version.
|
|
1733
1781
|
* @returns the current used lavalink version
|
|
@@ -1824,7 +1872,7 @@ var LavalinkNode = class {
|
|
|
1824
1872
|
*/
|
|
1825
1873
|
syncPlayerData(data, res) {
|
|
1826
1874
|
if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 0) {
|
|
1827
|
-
const player = this.
|
|
1875
|
+
const player = this._LManager.getPlayer(data.guildId);
|
|
1828
1876
|
if (!player) return;
|
|
1829
1877
|
if (typeof data.playerOptions.paused !== "undefined") {
|
|
1830
1878
|
player.paused = data.playerOptions.paused;
|
|
@@ -1836,8 +1884,8 @@ var LavalinkNode = class {
|
|
|
1836
1884
|
}
|
|
1837
1885
|
if (typeof data.playerOptions.voice !== "undefined") player.voice = data.playerOptions.voice;
|
|
1838
1886
|
if (typeof data.playerOptions.volume !== "undefined") {
|
|
1839
|
-
if (this.
|
|
1840
|
-
player.volume = Math.round(data.playerOptions.volume / this.
|
|
1887
|
+
if (this._LManager.options.playerOptions.volumeDecrementer) {
|
|
1888
|
+
player.volume = Math.round(data.playerOptions.volume / this._LManager.options.playerOptions.volumeDecrementer);
|
|
1841
1889
|
player.lavalinkVolume = Math.round(data.playerOptions.volume);
|
|
1842
1890
|
} else {
|
|
1843
1891
|
player.volume = Math.round(data.playerOptions.volume);
|
|
@@ -1861,7 +1909,7 @@ var LavalinkNode = class {
|
|
|
1861
1909
|
}
|
|
1862
1910
|
}
|
|
1863
1911
|
if (res?.guildId === "string" && typeof res?.voice !== "undefined") {
|
|
1864
|
-
const player = this.
|
|
1912
|
+
const player = this._LManager.getPlayer(data.guildId);
|
|
1865
1913
|
if (!player) return;
|
|
1866
1914
|
if (typeof res?.voice?.connected === "boolean" && res.voice.connected === false) {
|
|
1867
1915
|
player.destroy("LavalinkNoVoice" /* LavalinkNoVoice */);
|
|
@@ -1982,6 +2030,7 @@ var LavalinkNode = class {
|
|
|
1982
2030
|
const errorString = `Lavalink Node (${this.restAddress}) does not provide any /${this.version}/info`;
|
|
1983
2031
|
throw new Error(errorString);
|
|
1984
2032
|
}
|
|
2033
|
+
this.info.isNodelink = !!this.info.isNodelink;
|
|
1985
2034
|
this.NodeManager.emit("connect", this);
|
|
1986
2035
|
}
|
|
1987
2036
|
/** @private util function for handling closing events from websocket */
|
|
@@ -1994,7 +2043,7 @@ var LavalinkNode = class {
|
|
|
1994
2043
|
}
|
|
1995
2044
|
} catch (e) {
|
|
1996
2045
|
if (this.NodeManager?.LavalinkManager?.options?.advancedOptions?.enableDebugEvents) {
|
|
1997
|
-
this.
|
|
2046
|
+
this._LManager.emit("debug", "SocketCleanupError" /* SocketCleanupError */, {
|
|
1998
2047
|
state: "warn",
|
|
1999
2048
|
message: `An error occurred during socket cleanup in close() (likely a race condition): ${e.message}`,
|
|
2000
2049
|
functionLayer: "LavalinkNode > close()"
|
|
@@ -2010,9 +2059,9 @@ var LavalinkNode = class {
|
|
|
2010
2059
|
this.reconnect();
|
|
2011
2060
|
}
|
|
2012
2061
|
}
|
|
2013
|
-
this.
|
|
2014
|
-
if (!this.
|
|
2015
|
-
if (this.
|
|
2062
|
+
this._LManager.players.filter((p) => p?.node?.options?.id === this?.options?.id).forEach((p) => {
|
|
2063
|
+
if (!this._LManager.options.autoMove) return p.playing = false;
|
|
2064
|
+
if (this._LManager.options.autoMove) {
|
|
2016
2065
|
if (this.NodeManager.nodes.filter((n) => n.connected).size === 0)
|
|
2017
2066
|
return p.playing = false;
|
|
2018
2067
|
p.moveNode();
|
|
@@ -2053,17 +2102,12 @@ var LavalinkNode = class {
|
|
|
2053
2102
|
break;
|
|
2054
2103
|
case "playerUpdate":
|
|
2055
2104
|
{
|
|
2056
|
-
const player = this.
|
|
2057
|
-
if (!player) {
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
|
|
2063
|
-
});
|
|
2064
|
-
}
|
|
2065
|
-
return;
|
|
2066
|
-
}
|
|
2105
|
+
const player = this._LManager.getPlayer(payload.guildId);
|
|
2106
|
+
if (!player) return this._emitDebugEvent("PlayerUpdateNoPlayer" /* PlayerUpdateNoPlayer */, {
|
|
2107
|
+
state: "error",
|
|
2108
|
+
message: `PlayerUpdate Event Triggered, but no player found of payload.guildId: ${payload.guildId}`,
|
|
2109
|
+
functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
|
|
2110
|
+
});
|
|
2067
2111
|
const oldPlayer = player?.toJSON();
|
|
2068
2112
|
player.lastPositionChange = Date.now();
|
|
2069
2113
|
player.lastPosition = payload.state.position || 0;
|
|
@@ -2072,16 +2116,14 @@ var LavalinkNode = class {
|
|
|
2072
2116
|
if (!player.createdTimeStamp && payload.state.time) player.createdTimeStamp = payload.state.time;
|
|
2073
2117
|
if (player.filterManager.filterUpdatedState === true && ((player.queue.current?.info?.duration || 0) <= (player.LavalinkManager.options.advancedOptions.maxFilterFixDuration || 6e5) || player.queue.current?.info?.uri && (0, import_path.isAbsolute)(player.queue.current?.info?.uri))) {
|
|
2074
2118
|
player.filterManager.filterUpdatedState = false;
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
});
|
|
2081
|
-
}
|
|
2119
|
+
this._emitDebugEvent("PlayerUpdateFilterFixApply" /* PlayerUpdateFilterFixApply */, {
|
|
2120
|
+
state: "log",
|
|
2121
|
+
message: `Fixing FilterState on "${player.guildId}" because player.options.instaUpdateFiltersFix === true`,
|
|
2122
|
+
functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
|
|
2123
|
+
});
|
|
2082
2124
|
await player.seek(player.position);
|
|
2083
2125
|
}
|
|
2084
|
-
this.
|
|
2126
|
+
this._LManager.emit("playerUpdate", oldPlayer, player);
|
|
2085
2127
|
}
|
|
2086
2128
|
break;
|
|
2087
2129
|
case "event":
|
|
@@ -2095,14 +2137,12 @@ var LavalinkNode = class {
|
|
|
2095
2137
|
try {
|
|
2096
2138
|
this.NodeManager.emit("resumed", this, payload, await this.fetchAllPlayers());
|
|
2097
2139
|
} catch (e) {
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2140
|
+
this._emitDebugEvent("ResumingFetchingError" /* ResumingFetchingError */, {
|
|
2141
|
+
state: "error",
|
|
2142
|
+
message: `Failed to fetch players for resumed event, falling back without players array`,
|
|
2143
|
+
error: e,
|
|
2144
|
+
functionLayer: "LavalinkNode > nodeEvent > resumed"
|
|
2145
|
+
});
|
|
2106
2146
|
this.NodeManager.emit("resumed", this, payload, []);
|
|
2107
2147
|
}
|
|
2108
2148
|
}
|
|
@@ -2115,7 +2155,7 @@ var LavalinkNode = class {
|
|
|
2115
2155
|
/** @private middleware util function for handling all kind of events from websocket */
|
|
2116
2156
|
async handleEvent(payload) {
|
|
2117
2157
|
if (!payload?.guildId) return;
|
|
2118
|
-
const player = this.
|
|
2158
|
+
const player = this._LManager.getPlayer(payload.guildId);
|
|
2119
2159
|
if (!player) return;
|
|
2120
2160
|
switch (payload.type) {
|
|
2121
2161
|
case "TrackStartEvent":
|
|
@@ -2161,7 +2201,7 @@ var LavalinkNode = class {
|
|
|
2161
2201
|
return;
|
|
2162
2202
|
}
|
|
2163
2203
|
getTrackOfPayload(payload) {
|
|
2164
|
-
return "track" in payload ? this.
|
|
2204
|
+
return "track" in payload ? this._LManager.utils.buildTrack(payload.track, void 0) : null;
|
|
2165
2205
|
}
|
|
2166
2206
|
/** @private util function for handling trackStart event */
|
|
2167
2207
|
async trackStart(player, track, payload) {
|
|
@@ -2169,31 +2209,26 @@ var LavalinkNode = class {
|
|
|
2169
2209
|
player.playing = true;
|
|
2170
2210
|
player.paused = false;
|
|
2171
2211
|
}
|
|
2172
|
-
if (this.
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
return;
|
|
2212
|
+
if (this._LManager.options?.emitNewSongsOnly === true && player.queue.previous[0]?.info?.identifier === track?.info?.identifier) {
|
|
2213
|
+
return this._emitDebugEvent("TrackStartNewSongsOnly" /* TrackStartNewSongsOnly */, {
|
|
2214
|
+
state: "log",
|
|
2215
|
+
message: `TrackStart not Emitting, because playing the previous song again.`,
|
|
2216
|
+
functionLayer: "LavalinkNode > trackStart()"
|
|
2217
|
+
});
|
|
2181
2218
|
}
|
|
2182
2219
|
if (!player.queue.current) {
|
|
2183
2220
|
player.queue.current = this.getTrackOfPayload(payload);
|
|
2184
2221
|
if (player.queue.current) {
|
|
2185
2222
|
await player.queue.utils.save();
|
|
2186
2223
|
} else {
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
});
|
|
2193
|
-
}
|
|
2224
|
+
this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
|
|
2225
|
+
state: "warn",
|
|
2226
|
+
message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
|
|
2227
|
+
functionLayer: "LavalinkNode > trackStart()"
|
|
2228
|
+
});
|
|
2194
2229
|
}
|
|
2195
2230
|
}
|
|
2196
|
-
this.
|
|
2231
|
+
this._LManager.emit("trackStart", player, player.queue.current, payload);
|
|
2197
2232
|
return;
|
|
2198
2233
|
}
|
|
2199
2234
|
/** @private util function for handling trackEnd event */
|
|
@@ -2201,14 +2236,12 @@ var LavalinkNode = class {
|
|
|
2201
2236
|
if (player.get("internal_nodeChanging") === true) return;
|
|
2202
2237
|
const trackToUse = track || this.getTrackOfPayload(payload);
|
|
2203
2238
|
if (payload.reason === "replaced") {
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
}
|
|
2211
|
-
this.NodeManager.LavalinkManager.emit("trackEnd", player, trackToUse, payload);
|
|
2239
|
+
this._emitDebugEvent("TrackEndReplaced" /* TrackEndReplaced */, {
|
|
2240
|
+
state: "warn",
|
|
2241
|
+
message: `TrackEnd Event does not handle any playback, because the track was replaced.`,
|
|
2242
|
+
functionLayer: "LavalinkNode > trackEnd()"
|
|
2243
|
+
});
|
|
2244
|
+
this._LManager.emit("trackEnd", player, trackToUse, payload);
|
|
2212
2245
|
return;
|
|
2213
2246
|
}
|
|
2214
2247
|
if (!player.queue.tracks.length && (player.repeatMode === "off" || player.get("internal_stopPlaying"))) return this.queueEnd(player, track, payload);
|
|
@@ -2216,8 +2249,8 @@ var LavalinkNode = class {
|
|
|
2216
2249
|
if (player.get("internal_destroystatus") === true) return;
|
|
2217
2250
|
await queueTrackEnd(player);
|
|
2218
2251
|
if (!player.queue.current) return this.queueEnd(player, trackToUse, payload);
|
|
2219
|
-
this.
|
|
2220
|
-
if (this.
|
|
2252
|
+
this._LManager.emit("trackEnd", player, trackToUse, payload);
|
|
2253
|
+
if (this._LManager.options.autoSkip && player.queue.current) {
|
|
2221
2254
|
player.play({ noReplace: true });
|
|
2222
2255
|
}
|
|
2223
2256
|
return;
|
|
@@ -2230,30 +2263,28 @@ var LavalinkNode = class {
|
|
|
2230
2263
|
}
|
|
2231
2264
|
if (!player.queue.current) return this.queueEnd(player, trackToUse, payload);
|
|
2232
2265
|
player.set("internal_skipped", false);
|
|
2233
|
-
this.
|
|
2234
|
-
if (this.
|
|
2266
|
+
this._LManager.emit("trackEnd", player, trackToUse, payload);
|
|
2267
|
+
if (this._LManager.options.autoSkip && player.queue.current) {
|
|
2235
2268
|
player.play({ noReplace: true });
|
|
2236
2269
|
}
|
|
2237
2270
|
return;
|
|
2238
2271
|
}
|
|
2239
2272
|
/** @private util function for handling trackStuck event */
|
|
2240
2273
|
async trackStuck(player, track, payload) {
|
|
2241
|
-
if (this.
|
|
2242
|
-
const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this.
|
|
2274
|
+
if (this._LManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
|
|
2275
|
+
const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this._LManager.options.playerOptions.maxErrorsPerTime?.threshold);
|
|
2243
2276
|
player.set("internal_erroredTracksTimestamps", [...oldTimestamps, Date.now()]);
|
|
2244
|
-
if (oldTimestamps.length > this.
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
});
|
|
2251
|
-
}
|
|
2277
|
+
if (oldTimestamps.length > this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
|
|
2278
|
+
this._emitDebugEvent("TrackStuckMaxTracksErroredPerTime" /* TrackStuckMaxTracksErroredPerTime */, {
|
|
2279
|
+
state: "log",
|
|
2280
|
+
message: `trackStuck Event was triggered too often within a given threshold (LavalinkManager.options.playerOptions.maxErrorsPerTime). Threshold: "${this._LManager.options.playerOptions.maxErrorsPerTime?.threshold}ms", maxAmount: "${this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount}"`,
|
|
2281
|
+
functionLayer: "LavalinkNode > trackStuck()"
|
|
2282
|
+
});
|
|
2252
2283
|
player.destroy("TrackStuckMaxTracksErroredPerTime" /* TrackStuckMaxTracksErroredPerTime */);
|
|
2253
2284
|
return;
|
|
2254
2285
|
}
|
|
2255
2286
|
}
|
|
2256
|
-
this.
|
|
2287
|
+
this._LManager.emit("trackStuck", player, track || this.getTrackOfPayload(payload), payload);
|
|
2257
2288
|
if (!player.queue.tracks.length && (player.repeatMode === "off" || player.get("internal_stopPlaying"))) {
|
|
2258
2289
|
try {
|
|
2259
2290
|
await player.node.updatePlayer({ guildId: player.guildId, playerOptions: { track: { encoded: null } } });
|
|
@@ -2266,54 +2297,52 @@ var LavalinkNode = class {
|
|
|
2266
2297
|
if (!player.queue.current) {
|
|
2267
2298
|
return this.queueEnd(player, track || this.getTrackOfPayload(payload), payload);
|
|
2268
2299
|
}
|
|
2269
|
-
if (this.
|
|
2300
|
+
if (this._LManager.options.autoSkip && player.queue.current) {
|
|
2270
2301
|
player.play({ track: player.queue.current, noReplace: false });
|
|
2271
2302
|
}
|
|
2272
2303
|
return;
|
|
2273
2304
|
}
|
|
2274
2305
|
/** @private util function for handling trackError event */
|
|
2275
2306
|
async trackError(player, track, payload) {
|
|
2276
|
-
if (this.
|
|
2277
|
-
const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this.
|
|
2307
|
+
if (this._LManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
|
|
2308
|
+
const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this._LManager.options.playerOptions.maxErrorsPerTime?.threshold);
|
|
2278
2309
|
player.set("internal_erroredTracksTimestamps", [...oldTimestamps, Date.now()]);
|
|
2279
|
-
if (oldTimestamps.length > this.
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
});
|
|
2286
|
-
}
|
|
2310
|
+
if (oldTimestamps.length > this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
|
|
2311
|
+
this._emitDebugEvent("TrackErrorMaxTracksErroredPerTime" /* TrackErrorMaxTracksErroredPerTime */, {
|
|
2312
|
+
state: "log",
|
|
2313
|
+
message: `TrackError Event was triggered too often within a given threshold (LavalinkManager.options.playerOptions.maxErrorsPerTime). Threshold: "${this._LManager.options.playerOptions.maxErrorsPerTime?.threshold}ms", maxAmount: "${this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount}"`,
|
|
2314
|
+
functionLayer: "LavalinkNode > trackError()"
|
|
2315
|
+
});
|
|
2287
2316
|
player.destroy("TrackErrorMaxTracksErroredPerTime" /* TrackErrorMaxTracksErroredPerTime */);
|
|
2288
2317
|
return;
|
|
2289
2318
|
}
|
|
2290
2319
|
}
|
|
2291
|
-
this.
|
|
2320
|
+
this._LManager.emit("trackError", player, track || this.getTrackOfPayload(payload), payload);
|
|
2292
2321
|
return;
|
|
2293
2322
|
}
|
|
2294
2323
|
/** @private util function for handling socketClosed event */
|
|
2295
2324
|
socketClosed(player, payload) {
|
|
2296
|
-
this.
|
|
2325
|
+
this._LManager.emit("playerSocketClosed", player, payload);
|
|
2297
2326
|
return;
|
|
2298
2327
|
}
|
|
2299
2328
|
/** @private util function for handling SponsorBlock Segmentloaded event */
|
|
2300
2329
|
SponsorBlockSegmentLoaded(player, track, payload) {
|
|
2301
|
-
this.
|
|
2330
|
+
this._LManager.emit("SegmentsLoaded", player, track || this.getTrackOfPayload(payload), payload);
|
|
2302
2331
|
return;
|
|
2303
2332
|
}
|
|
2304
2333
|
/** @private util function for handling SponsorBlock SegmentSkipped event */
|
|
2305
2334
|
SponsorBlockSegmentSkipped(player, track, payload) {
|
|
2306
|
-
this.
|
|
2335
|
+
this._LManager.emit("SegmentSkipped", player, track || this.getTrackOfPayload(payload), payload);
|
|
2307
2336
|
return;
|
|
2308
2337
|
}
|
|
2309
2338
|
/** @private util function for handling SponsorBlock Chaptersloaded event */
|
|
2310
2339
|
SponsorBlockChaptersLoaded(player, track, payload) {
|
|
2311
|
-
this.
|
|
2340
|
+
this._LManager.emit("ChaptersLoaded", player, track || this.getTrackOfPayload(payload), payload);
|
|
2312
2341
|
return;
|
|
2313
2342
|
}
|
|
2314
2343
|
/** @private util function for handling SponsorBlock Chaptersstarted event */
|
|
2315
2344
|
SponsorBlockChapterStarted(player, track, payload) {
|
|
2316
|
-
this.
|
|
2345
|
+
this._LManager.emit("ChapterStarted", player, track || this.getTrackOfPayload(payload), payload);
|
|
2317
2346
|
return;
|
|
2318
2347
|
}
|
|
2319
2348
|
/**
|
|
@@ -2328,7 +2357,7 @@ var LavalinkNode = class {
|
|
|
2328
2357
|
* ```
|
|
2329
2358
|
*/
|
|
2330
2359
|
async getSponsorBlock(player) {
|
|
2331
|
-
if (!this.info
|
|
2360
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
|
|
2332
2361
|
return await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`);
|
|
2333
2362
|
}
|
|
2334
2363
|
/**
|
|
@@ -2343,7 +2372,7 @@ var LavalinkNode = class {
|
|
|
2343
2372
|
* ```
|
|
2344
2373
|
*/
|
|
2345
2374
|
async setSponsorBlock(player, segments = ["sponsor", "selfpromo"]) {
|
|
2346
|
-
if (!this.info
|
|
2375
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
|
|
2347
2376
|
if (!segments.length) throw new RangeError("No Segments provided. Did you ment to use 'deleteSponsorBlock'?");
|
|
2348
2377
|
if (segments.some((v) => !validSponsorBlocks.includes(v.toLowerCase()))) throw new SyntaxError(`You provided a sponsorblock which isn't valid, valid ones are: ${validSponsorBlocks.map((v) => `'${v}'`).join(", ")}`);
|
|
2349
2378
|
await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, (r) => {
|
|
@@ -2352,13 +2381,11 @@ var LavalinkNode = class {
|
|
|
2352
2381
|
r.body = safeStringify(segments.map((v) => v.toLowerCase()));
|
|
2353
2382
|
});
|
|
2354
2383
|
player.set("internal_sponsorBlockCategories", segments.map((v) => v.toLowerCase()));
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
});
|
|
2361
|
-
}
|
|
2384
|
+
this._emitDebugEvent("SetSponsorBlock" /* SetSponsorBlock */, {
|
|
2385
|
+
state: "log",
|
|
2386
|
+
message: `SponsorBlock was set for Player: ${player.guildId} to: ${segments.map((v) => `'${v.toLowerCase()}'`).join(", ")}`,
|
|
2387
|
+
functionLayer: "LavalinkNode > setSponsorBlock()"
|
|
2388
|
+
});
|
|
2362
2389
|
return;
|
|
2363
2390
|
}
|
|
2364
2391
|
/**
|
|
@@ -2373,18 +2400,16 @@ var LavalinkNode = class {
|
|
|
2373
2400
|
* ```
|
|
2374
2401
|
*/
|
|
2375
2402
|
async deleteSponsorBlock(player) {
|
|
2376
|
-
if (!this.info
|
|
2403
|
+
if (this._checkForPlugins && !this.info?.plugins?.find?.((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
|
|
2377
2404
|
await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, (r) => {
|
|
2378
2405
|
r.method = "DELETE";
|
|
2379
2406
|
});
|
|
2380
2407
|
player.set("internal_sponsorBlockCategories", []);
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
});
|
|
2387
|
-
}
|
|
2408
|
+
this._emitDebugEvent("DeleteSponsorBlock" /* DeleteSponsorBlock */, {
|
|
2409
|
+
state: "log",
|
|
2410
|
+
message: `SponsorBlock was deleted for Player: ${player.guildId}`,
|
|
2411
|
+
functionLayer: "LavalinkNode > deleteSponsorBlock()"
|
|
2412
|
+
});
|
|
2388
2413
|
return;
|
|
2389
2414
|
}
|
|
2390
2415
|
/** private util function for handling the queue end event */
|
|
@@ -2393,46 +2418,38 @@ var LavalinkNode = class {
|
|
|
2393
2418
|
player.queue.current = null;
|
|
2394
2419
|
player.playing = false;
|
|
2395
2420
|
player.set("internal_stopPlaying", void 0);
|
|
2396
|
-
|
|
2397
|
-
|
|
2421
|
+
this._emitDebugEvent("QueueEnded" /* QueueEnded */, {
|
|
2422
|
+
state: "log",
|
|
2423
|
+
message: `Queue Ended because no more Tracks were in the Queue, due to EventName: "${payload.type}"`,
|
|
2424
|
+
functionLayer: "LavalinkNode > queueEnd()"
|
|
2425
|
+
});
|
|
2426
|
+
if (typeof this._LManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction === "function" && typeof player.get("internal_autoplayStopPlaying") === "undefined") {
|
|
2427
|
+
this._emitDebugEvent("AutoplayExecution" /* AutoplayExecution */, {
|
|
2398
2428
|
state: "log",
|
|
2399
|
-
message: `
|
|
2400
|
-
functionLayer: "LavalinkNode > queueEnd()"
|
|
2429
|
+
message: `Now Triggering Autoplay.`,
|
|
2430
|
+
functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
|
|
2401
2431
|
});
|
|
2402
|
-
}
|
|
2403
|
-
if (typeof this.NodeManager.LavalinkManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction === "function" && typeof player.get("internal_autoplayStopPlaying") === "undefined") {
|
|
2404
|
-
if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
|
|
2405
|
-
this.NodeManager.LavalinkManager.emit("debug", "AutoplayExecution" /* AutoplayExecution */, {
|
|
2406
|
-
state: "log",
|
|
2407
|
-
message: `Now Triggering Autoplay.`,
|
|
2408
|
-
functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
|
|
2409
|
-
});
|
|
2410
|
-
}
|
|
2411
2432
|
const previousAutoplayTime = player.get("internal_previousautoplay");
|
|
2412
2433
|
const duration = previousAutoplayTime ? Date.now() - previousAutoplayTime : 0;
|
|
2413
|
-
if (!duration || duration > this.
|
|
2414
|
-
await this.
|
|
2434
|
+
if (!duration || duration > this._LManager.options.playerOptions.minAutoPlayMs || !!player.get("internal_skipped")) {
|
|
2435
|
+
await this._LManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction(player, track);
|
|
2415
2436
|
player.set("internal_previousautoplay", Date.now());
|
|
2416
2437
|
if (player.queue.tracks.length > 0) await queueTrackEnd(player);
|
|
2417
|
-
else
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
if (
|
|
2425
|
-
|
|
2426
|
-
if (this.NodeManager.LavalinkManager.options.autoSkip) return player.play({ noReplace: true, paused: false });
|
|
2427
|
-
}
|
|
2438
|
+
else this._emitDebugEvent("AutoplayNoSongsAdded" /* AutoplayNoSongsAdded */, {
|
|
2439
|
+
state: "warn",
|
|
2440
|
+
message: `Autoplay was triggered but no songs were added to the queue.`,
|
|
2441
|
+
functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
if (player.queue.current) {
|
|
2445
|
+
if (payload.type === "TrackEndEvent") this._LManager.emit("trackEnd", player, track, payload);
|
|
2446
|
+
if (this._LManager.options.autoSkip) return player.play({ noReplace: true, paused: false });
|
|
2428
2447
|
} else {
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
});
|
|
2435
|
-
}
|
|
2448
|
+
this._emitDebugEvent("AutoplayThresholdSpamLimiter" /* AutoplayThresholdSpamLimiter */, {
|
|
2449
|
+
state: "warn",
|
|
2450
|
+
message: `Autoplay was triggered after the previousautoplay too early. Threshold is: ${this._LManager.options.playerOptions.minAutoPlayMs}ms and the Duration was ${duration}ms`,
|
|
2451
|
+
functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
|
|
2452
|
+
});
|
|
2436
2453
|
}
|
|
2437
2454
|
}
|
|
2438
2455
|
player.set("internal_skipped", false);
|
|
@@ -2445,31 +2462,29 @@ var LavalinkNode = class {
|
|
|
2445
2462
|
if (payload?.reason !== "stopped") {
|
|
2446
2463
|
await player.queue.utils.save();
|
|
2447
2464
|
}
|
|
2448
|
-
if (typeof this.
|
|
2449
|
-
if (this.
|
|
2465
|
+
if (typeof this._LManager.options.playerOptions?.onEmptyQueue?.destroyAfterMs === "number" && !isNaN(this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs) && this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs >= 0) {
|
|
2466
|
+
if (this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs === 0) {
|
|
2450
2467
|
player.destroy("QueueEmpty" /* QueueEmpty */);
|
|
2451
2468
|
return;
|
|
2452
2469
|
} else {
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
}
|
|
2460
|
-
this.NodeManager.LavalinkManager.emit("playerQueueEmptyStart", player, this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs);
|
|
2470
|
+
this._emitDebugEvent("TriggerQueueEmptyInterval" /* TriggerQueueEmptyInterval */, {
|
|
2471
|
+
state: "log",
|
|
2472
|
+
message: `Trigger Queue Empty Interval was Triggered because playerOptions.onEmptyQueue.destroyAfterMs is set to ${this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs}ms`,
|
|
2473
|
+
functionLayer: "LavalinkNode > queueEnd() > destroyAfterMs"
|
|
2474
|
+
});
|
|
2475
|
+
this._LManager.emit("playerQueueEmptyStart", player, this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs);
|
|
2461
2476
|
if (player.get("internal_queueempty")) clearTimeout(player.get("internal_queueempty"));
|
|
2462
2477
|
player.set("internal_queueempty", setTimeout(() => {
|
|
2463
2478
|
player.set("internal_queueempty", void 0);
|
|
2464
2479
|
if (player.queue.current) {
|
|
2465
|
-
return this.
|
|
2480
|
+
return this._LManager.emit("playerQueueEmptyCancel", player);
|
|
2466
2481
|
}
|
|
2467
|
-
this.
|
|
2482
|
+
this._LManager.emit("playerQueueEmptyEnd", player);
|
|
2468
2483
|
player.destroy("QueueEmpty" /* QueueEmpty */);
|
|
2469
|
-
}, this.
|
|
2484
|
+
}, this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs));
|
|
2470
2485
|
}
|
|
2471
2486
|
}
|
|
2472
|
-
this.
|
|
2487
|
+
this._LManager.emit("queueEnd", player, track, payload);
|
|
2473
2488
|
return;
|
|
2474
2489
|
}
|
|
2475
2490
|
/**
|
|
@@ -2485,16 +2500,14 @@ var LavalinkNode = class {
|
|
|
2485
2500
|
if (player.queue.current) {
|
|
2486
2501
|
await player.queue.utils.save();
|
|
2487
2502
|
} else {
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2503
|
+
this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
|
|
2504
|
+
state: "warn",
|
|
2505
|
+
message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
|
|
2506
|
+
functionLayer: "LavalinkNode > trackStart()"
|
|
2507
|
+
});
|
|
2495
2508
|
}
|
|
2496
2509
|
}
|
|
2497
|
-
this.
|
|
2510
|
+
this._LManager.emit("LyricsLine", player, track, payload);
|
|
2498
2511
|
return;
|
|
2499
2512
|
}
|
|
2500
2513
|
/**
|
|
@@ -2510,16 +2523,14 @@ var LavalinkNode = class {
|
|
|
2510
2523
|
if (player.queue.current) {
|
|
2511
2524
|
await player.queue.utils.save();
|
|
2512
2525
|
} else {
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
});
|
|
2519
|
-
}
|
|
2526
|
+
this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
|
|
2527
|
+
state: "warn",
|
|
2528
|
+
message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
|
|
2529
|
+
functionLayer: "LavalinkNode > trackStart()"
|
|
2530
|
+
});
|
|
2520
2531
|
}
|
|
2521
2532
|
}
|
|
2522
|
-
this.
|
|
2533
|
+
this._LManager.emit("LyricsFound", player, track, payload);
|
|
2523
2534
|
return;
|
|
2524
2535
|
}
|
|
2525
2536
|
/**
|
|
@@ -2535,16 +2546,14 @@ var LavalinkNode = class {
|
|
|
2535
2546
|
if (player.queue.current) {
|
|
2536
2547
|
await player.queue.utils.save();
|
|
2537
2548
|
} else {
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
});
|
|
2544
|
-
}
|
|
2549
|
+
this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
|
|
2550
|
+
state: "warn",
|
|
2551
|
+
message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
|
|
2552
|
+
functionLayer: "LavalinkNode > trackStart()"
|
|
2553
|
+
});
|
|
2545
2554
|
}
|
|
2546
2555
|
}
|
|
2547
|
-
this.
|
|
2556
|
+
this._LManager.emit("LyricsNotFound", player, track, payload);
|
|
2548
2557
|
return;
|
|
2549
2558
|
}
|
|
2550
2559
|
};
|
|
@@ -2906,6 +2915,21 @@ var FilterManager = class {
|
|
|
2906
2915
|
data = structuredClone(DEFAULT_FILTER_DATAS);
|
|
2907
2916
|
/** The Player assigned to this Filter Manager */
|
|
2908
2917
|
player;
|
|
2918
|
+
get _LManager() {
|
|
2919
|
+
return this.player.LavalinkManager;
|
|
2920
|
+
}
|
|
2921
|
+
/**
|
|
2922
|
+
* Returns wether the plugin validations are enabled or not
|
|
2923
|
+
*/
|
|
2924
|
+
get _checkForPlugins() {
|
|
2925
|
+
return !!this._LManager.options?.autoChecks?.pluginValidations;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* Returns wether the source validations are enabled or not
|
|
2929
|
+
*/
|
|
2930
|
+
get _checkForSources() {
|
|
2931
|
+
return !!this._LManager.options?.autoChecks?.sourcesValidations;
|
|
2932
|
+
}
|
|
2909
2933
|
/** The Constructor for the FilterManager */
|
|
2910
2934
|
constructor(player) {
|
|
2911
2935
|
this.player = player;
|
|
@@ -2942,13 +2966,13 @@ var FilterManager = class {
|
|
|
2942
2966
|
if (!this.filters.karaoke) delete sendData.karaoke;
|
|
2943
2967
|
if (!this.filters.rotation) delete sendData.rotation;
|
|
2944
2968
|
if (this.filters.audioOutput === "stereo") delete sendData.channelMix;
|
|
2945
|
-
if (Object.values(this.data.timescale).every((v) => v === 1)) delete sendData.timescale;
|
|
2969
|
+
if (Object.values(this.data.timescale ?? {}).every((v) => v === 1)) delete sendData.timescale;
|
|
2946
2970
|
if (!this.player.node.sessionId) throw new Error("The Lavalink-Node is either not ready or not up to date");
|
|
2947
2971
|
sendData.equalizer = [...this.equalizerBands];
|
|
2948
2972
|
if (sendData.equalizer.length === 0) delete sendData.equalizer;
|
|
2949
2973
|
for (const key of Object.keys(sendData)) {
|
|
2950
2974
|
if (key === "pluginFilters") {
|
|
2951
|
-
} else if (this.
|
|
2975
|
+
} else if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.(key)) delete sendData[key];
|
|
2952
2976
|
}
|
|
2953
2977
|
const now = performance.now();
|
|
2954
2978
|
if (this.player.options.instaUpdateFiltersFix === true) this.filterUpdatedState = true;
|
|
@@ -3088,7 +3112,7 @@ var FilterManager = class {
|
|
|
3088
3112
|
* ```
|
|
3089
3113
|
*/
|
|
3090
3114
|
async setAudioOutput(type) {
|
|
3091
|
-
if (this.
|
|
3115
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("channelMix")) throw new Error("Node#Info#filters does not include the 'channelMix' Filter (Node has it not enable)");
|
|
3092
3116
|
if (!type || !audioOutputsData[type]) throw "Invalid audio type added, must be 'mono' / 'stereo' / 'left' / 'right'";
|
|
3093
3117
|
this.data = this.data ?? {};
|
|
3094
3118
|
this.data.channelMix = audioOutputsData[type];
|
|
@@ -3108,7 +3132,7 @@ var FilterManager = class {
|
|
|
3108
3132
|
* ```
|
|
3109
3133
|
*/
|
|
3110
3134
|
async setSpeed(speed = 1) {
|
|
3111
|
-
if (this.
|
|
3135
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
|
|
3112
3136
|
this.data = this.data ?? {};
|
|
3113
3137
|
this.filters.nightcore = false;
|
|
3114
3138
|
this.filters.vaporwave = false;
|
|
@@ -3129,7 +3153,7 @@ var FilterManager = class {
|
|
|
3129
3153
|
* ```
|
|
3130
3154
|
*/
|
|
3131
3155
|
async setPitch(pitch = 1) {
|
|
3132
|
-
if (this.
|
|
3156
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
|
|
3133
3157
|
this.data = this.data ?? {};
|
|
3134
3158
|
this.filters.nightcore = false;
|
|
3135
3159
|
this.filters.vaporwave = false;
|
|
@@ -3150,7 +3174,7 @@ var FilterManager = class {
|
|
|
3150
3174
|
* ```
|
|
3151
3175
|
*/
|
|
3152
3176
|
async setRate(rate = 1) {
|
|
3153
|
-
if (this.
|
|
3177
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
|
|
3154
3178
|
this.data = this.data ?? {};
|
|
3155
3179
|
this.filters.nightcore = false;
|
|
3156
3180
|
this.filters.vaporwave = false;
|
|
@@ -3174,7 +3198,7 @@ var FilterManager = class {
|
|
|
3174
3198
|
* ```
|
|
3175
3199
|
*/
|
|
3176
3200
|
async toggleRotation(rotationHz = 0.2) {
|
|
3177
|
-
if (this.
|
|
3201
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("rotation")) throw new Error("Node#Info#filters does not include the 'rotation' Filter (Node has it not enable)");
|
|
3178
3202
|
this.data = this.data ?? {};
|
|
3179
3203
|
this.data.rotation = this.filters.rotation ? DEFAULT_FILTER_DATAS.rotation : { rotationHz };
|
|
3180
3204
|
this.filters.rotation = !this.filters.rotation;
|
|
@@ -3197,7 +3221,7 @@ var FilterManager = class {
|
|
|
3197
3221
|
* ```
|
|
3198
3222
|
*/
|
|
3199
3223
|
async toggleVibrato(frequency = 10, depth = 1) {
|
|
3200
|
-
if (this.
|
|
3224
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("vibrato")) throw new Error("Node#Info#filters does not include the 'vibrato' Filter (Node has it not enable)");
|
|
3201
3225
|
this.data = this.data ?? {};
|
|
3202
3226
|
this.data.vibrato = this.filters.vibrato ? DEFAULT_FILTER_DATAS.vibrato : { depth, frequency };
|
|
3203
3227
|
this.filters.vibrato = !this.filters.vibrato;
|
|
@@ -3220,7 +3244,7 @@ var FilterManager = class {
|
|
|
3220
3244
|
* ```
|
|
3221
3245
|
*/
|
|
3222
3246
|
async toggleTremolo(frequency = 4, depth = 0.8) {
|
|
3223
|
-
if (this.
|
|
3247
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("tremolo")) throw new Error("Node#Info#filters does not include the 'tremolo' Filter (Node has it not enable)");
|
|
3224
3248
|
this.data = this.data ?? {};
|
|
3225
3249
|
this.data.tremolo = this.filters.tremolo ? DEFAULT_FILTER_DATAS.tremolo : { depth, frequency };
|
|
3226
3250
|
this.filters.tremolo = !this.filters.tremolo;
|
|
@@ -3242,7 +3266,7 @@ var FilterManager = class {
|
|
|
3242
3266
|
* ```
|
|
3243
3267
|
*/
|
|
3244
3268
|
async toggleLowPass(smoothing = 20) {
|
|
3245
|
-
if (this.
|
|
3269
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("lowPass")) throw new Error("Node#Info#filters does not include the 'lowPass' Filter (Node has it not enable)");
|
|
3246
3270
|
this.data = this.data ?? {};
|
|
3247
3271
|
this.data.lowPass = this.filters.lowPass ? DEFAULT_FILTER_DATAS.lowPass : { smoothing };
|
|
3248
3272
|
this.filters.lowPass = !this.filters.lowPass;
|
|
@@ -3269,8 +3293,8 @@ var FilterManager = class {
|
|
|
3269
3293
|
* ```
|
|
3270
3294
|
*/
|
|
3271
3295
|
toggleLowPass: async (boostFactor = 1, cutoffFrequency = 80) => {
|
|
3272
|
-
if (this.
|
|
3273
|
-
if (this.
|
|
3296
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
|
|
3297
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("low-pass")) throw new Error("Node#Info#filters does not include the 'low-pass' Filter (Node has it not enable)");
|
|
3274
3298
|
this.data = this.data ?? {};
|
|
3275
3299
|
this.data.pluginFilters = this.data.pluginFilters ?? {};
|
|
3276
3300
|
if (this.filters.lavalinkLavaDspxPlugin.lowPass) delete this.data.pluginFilters["low-pass"];
|
|
@@ -3295,8 +3319,8 @@ var FilterManager = class {
|
|
|
3295
3319
|
* ```
|
|
3296
3320
|
*/
|
|
3297
3321
|
toggleHighPass: async (boostFactor = 1, cutoffFrequency = 80) => {
|
|
3298
|
-
if (this.
|
|
3299
|
-
if (this.
|
|
3322
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
|
|
3323
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("high-pass")) throw new Error("Node#Info#filters does not include the 'high-pass' Filter (Node has it not enable)");
|
|
3300
3324
|
this.data = this.data ?? {};
|
|
3301
3325
|
this.data.pluginFilters = this.data.pluginFilters ?? {};
|
|
3302
3326
|
if (this.filters.lavalinkLavaDspxPlugin.highPass) delete this.data.pluginFilters["high-pass"];
|
|
@@ -3321,8 +3345,8 @@ var FilterManager = class {
|
|
|
3321
3345
|
* ```
|
|
3322
3346
|
*/
|
|
3323
3347
|
toggleNormalization: async (maxAmplitude = 0.75, adaptive = true) => {
|
|
3324
|
-
if (this.
|
|
3325
|
-
if (this.
|
|
3348
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
|
|
3349
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("normalization")) throw new Error("Node#Info#filters does not include the 'normalization' Filter (Node has it not enable)");
|
|
3326
3350
|
this.data = this.data ?? {};
|
|
3327
3351
|
this.data.pluginFilters = this.data.pluginFilters ?? {};
|
|
3328
3352
|
if (this.filters.lavalinkLavaDspxPlugin.normalization) delete this.data.pluginFilters.normalization;
|
|
@@ -3347,8 +3371,8 @@ var FilterManager = class {
|
|
|
3347
3371
|
* ```
|
|
3348
3372
|
*/
|
|
3349
3373
|
toggleEcho: async (decay = 0.5, echoLength = 0.5) => {
|
|
3350
|
-
if (this.
|
|
3351
|
-
if (this.
|
|
3374
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
|
|
3375
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("echo")) throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable)");
|
|
3352
3376
|
this.data = this.data ?? {};
|
|
3353
3377
|
this.data.pluginFilters = this.data.pluginFilters ?? {};
|
|
3354
3378
|
if (this.filters.lavalinkLavaDspxPlugin.echo) delete this.data.pluginFilters.echo;
|
|
@@ -3378,8 +3402,8 @@ var FilterManager = class {
|
|
|
3378
3402
|
* ```
|
|
3379
3403
|
*/
|
|
3380
3404
|
toggleEcho: async (delay = 4, decay = 0.8) => {
|
|
3381
|
-
if (this.
|
|
3382
|
-
if (this.
|
|
3405
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavalink-filter-plugin")) throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
|
|
3406
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("echo")) throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable aka not installed!)");
|
|
3383
3407
|
this.data = this.data ?? {};
|
|
3384
3408
|
const { echo, reverb } = DEFAULT_FILTER_DATAS.pluginFilters["lavalink-filter-plugin"];
|
|
3385
3409
|
this.data.pluginFilters = {
|
|
@@ -3409,8 +3433,8 @@ var FilterManager = class {
|
|
|
3409
3433
|
* ```
|
|
3410
3434
|
*/
|
|
3411
3435
|
toggleReverb: async (delays = [0.037, 0.042, 0.048, 0.053], gains = [0.84, 0.83, 0.82, 0.81]) => {
|
|
3412
|
-
if (this.
|
|
3413
|
-
if (this.
|
|
3436
|
+
if (this._checkForPlugins && !this.player?.node?.info?.plugins?.find?.((v) => v.name === "lavalink-filter-plugin")) throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
|
|
3437
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("reverb")) throw new Error("Node#Info#filters does not include the 'reverb' Filter (Node has it not enable aka not installed!)");
|
|
3414
3438
|
this.data = this.data ?? {};
|
|
3415
3439
|
const { echo, reverb } = DEFAULT_FILTER_DATAS.pluginFilters["lavalink-filter-plugin"];
|
|
3416
3440
|
this.data.pluginFilters = {
|
|
@@ -3442,7 +3466,7 @@ var FilterManager = class {
|
|
|
3442
3466
|
* ```
|
|
3443
3467
|
*/
|
|
3444
3468
|
async toggleNightcore(speed = 1.289999523162842, pitch = 1.289999523162842, rate = 0.9365999523162842) {
|
|
3445
|
-
if (this.
|
|
3469
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
|
|
3446
3470
|
this.data = this.data ?? {};
|
|
3447
3471
|
this.data.timescale = this.filters.nightcore ? DEFAULT_FILTER_DATAS.timescale : { speed, pitch, rate };
|
|
3448
3472
|
this.filters.nightcore = !this.filters.nightcore;
|
|
@@ -3468,7 +3492,7 @@ var FilterManager = class {
|
|
|
3468
3492
|
* ```
|
|
3469
3493
|
*/
|
|
3470
3494
|
async toggleVaporwave(speed = 0.8500000238418579, pitch = 0.800000011920929, rate = 1) {
|
|
3471
|
-
if (this.
|
|
3495
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
|
|
3472
3496
|
this.data = this.data ?? {};
|
|
3473
3497
|
this.data.timescale = this.filters.vaporwave ? DEFAULT_FILTER_DATAS.timescale : { speed, pitch, rate };
|
|
3474
3498
|
this.filters.vaporwave = !this.filters.vaporwave;
|
|
@@ -3495,7 +3519,7 @@ var FilterManager = class {
|
|
|
3495
3519
|
* ```
|
|
3496
3520
|
*/
|
|
3497
3521
|
async toggleKaraoke(level = 1, monoLevel = 1, filterBand = 220, filterWidth = 100) {
|
|
3498
|
-
if (this.
|
|
3522
|
+
if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.("karaoke")) throw new Error("Node#Info#filters does not include the 'karaoke' Filter (Node has it not enable)");
|
|
3499
3523
|
this.data = this.data ?? {};
|
|
3500
3524
|
this.data.karaoke = this.filters.karaoke ? DEFAULT_FILTER_DATAS.karaoke : { level, monoLevel, filterBand, filterWidth };
|
|
3501
3525
|
this.filters.karaoke = !this.filters.karaoke;
|
|
@@ -4012,6 +4036,15 @@ var Player = class {
|
|
|
4012
4036
|
};
|
|
4013
4037
|
/** Custom data for the player */
|
|
4014
4038
|
data = {};
|
|
4039
|
+
/**
|
|
4040
|
+
* Emits a debug event to the LavalinkManager
|
|
4041
|
+
* @param name name of the event
|
|
4042
|
+
* @param eventData event data
|
|
4043
|
+
*/
|
|
4044
|
+
_emitDebugEvent(name, eventData) {
|
|
4045
|
+
if (!this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) return;
|
|
4046
|
+
this.LavalinkManager.emit("debug", name, eventData);
|
|
4047
|
+
}
|
|
4015
4048
|
/**
|
|
4016
4049
|
* Create a new Player
|
|
4017
4050
|
* @param options
|
|
@@ -4027,8 +4060,8 @@ var Player = class {
|
|
|
4027
4060
|
this.textChannelId = this.options.textChannelId || null;
|
|
4028
4061
|
this.node = typeof this.options.node === "string" ? this.LavalinkManager.nodeManager.nodes.get(this.options.node) : this.options.node;
|
|
4029
4062
|
if (!this.node || typeof this.node.request !== "function") {
|
|
4030
|
-
if (typeof this.options.node === "string"
|
|
4031
|
-
this.
|
|
4063
|
+
if (typeof this.options.node === "string") {
|
|
4064
|
+
this._emitDebugEvent("PlayerCreateNodeNotFound" /* PlayerCreateNodeNotFound */, {
|
|
4032
4065
|
state: "warn",
|
|
4033
4066
|
message: `Player was created with provided node Id: ${this.options.node}, but no node with that Id was found.`,
|
|
4034
4067
|
functionLayer: "Player > constructor()"
|
|
@@ -4085,13 +4118,11 @@ var Player = class {
|
|
|
4085
4118
|
*/
|
|
4086
4119
|
async play(options = {}) {
|
|
4087
4120
|
if (this.get("internal_queueempty")) {
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
});
|
|
4094
|
-
}
|
|
4121
|
+
this._emitDebugEvent("PlayerPlayQueueEmptyTimeoutClear" /* PlayerPlayQueueEmptyTimeoutClear */, {
|
|
4122
|
+
state: "log",
|
|
4123
|
+
message: `Player was called to play something, while there was a queueEmpty Timeout set, clearing the timeout.`,
|
|
4124
|
+
functionLayer: "Player > play()"
|
|
4125
|
+
});
|
|
4095
4126
|
this.LavalinkManager.emit("playerQueueEmptyCancel", this);
|
|
4096
4127
|
clearTimeout(this.get("internal_queueempty"));
|
|
4097
4128
|
this.set("internal_queueempty", void 0);
|
|
@@ -4101,14 +4132,12 @@ var Player = class {
|
|
|
4101
4132
|
try {
|
|
4102
4133
|
await options.clientTrack.resolve(this);
|
|
4103
4134
|
} catch (error) {
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
});
|
|
4111
|
-
}
|
|
4135
|
+
this._emitDebugEvent("PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
|
|
4136
|
+
state: "error",
|
|
4137
|
+
error,
|
|
4138
|
+
message: `Player Play was called with clientTrack, Song is unresolved, but couldn't resolve it`,
|
|
4139
|
+
functionLayer: "Player > play() > resolve currentTrack"
|
|
4140
|
+
});
|
|
4112
4141
|
this.LavalinkManager.emit("trackError", this, this.queue.current, error);
|
|
4113
4142
|
if (options && "clientTrack" in options) delete options.clientTrack;
|
|
4114
4143
|
if (options && "track" in options) delete options.track;
|
|
@@ -4145,13 +4174,11 @@ var Player = class {
|
|
|
4145
4174
|
...options.track.userData
|
|
4146
4175
|
}
|
|
4147
4176
|
}).filter((v) => typeof v[1] !== "undefined"));
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
});
|
|
4154
|
-
}
|
|
4177
|
+
this._emitDebugEvent("PlayerPlayWithTrackReplace" /* PlayerPlayWithTrackReplace */, {
|
|
4178
|
+
state: "log",
|
|
4179
|
+
message: `Player was called to play something, with a specific track provided. Replacing the current Track and resolving the track on trackStart Event.`,
|
|
4180
|
+
functionLayer: "Player > play()"
|
|
4181
|
+
});
|
|
4155
4182
|
return this.node.updatePlayer({
|
|
4156
4183
|
guildId: this.guildId,
|
|
4157
4184
|
noReplace: false,
|
|
@@ -4168,13 +4195,11 @@ var Player = class {
|
|
|
4168
4195
|
}
|
|
4169
4196
|
if (!this.queue.current && this.queue.tracks.length) await queueTrackEnd(this);
|
|
4170
4197
|
if (this.queue.current && this.LavalinkManager.utils.isUnresolvedTrack(this.queue.current)) {
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
});
|
|
4177
|
-
}
|
|
4198
|
+
this._emitDebugEvent("PlayerPlayUnresolvedTrack" /* PlayerPlayUnresolvedTrack */, {
|
|
4199
|
+
state: "log",
|
|
4200
|
+
message: `Player Play was called, current Queue Song is unresolved, resolving the track.`,
|
|
4201
|
+
functionLayer: "Player > play()"
|
|
4202
|
+
});
|
|
4178
4203
|
try {
|
|
4179
4204
|
await this.queue.current.resolve(this);
|
|
4180
4205
|
if (typeof options.track?.userData === "object" && this.queue.current) this.queue.current.userData = {
|
|
@@ -4183,14 +4208,12 @@ var Player = class {
|
|
|
4183
4208
|
...options.track?.userData
|
|
4184
4209
|
};
|
|
4185
4210
|
} catch (error) {
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
});
|
|
4193
|
-
}
|
|
4211
|
+
this._emitDebugEvent("PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
|
|
4212
|
+
state: "error",
|
|
4213
|
+
error,
|
|
4214
|
+
message: `Player Play was called, current Queue Song is unresolved, but couldn't resolve it`,
|
|
4215
|
+
functionLayer: "Player > play() > resolve currentTrack"
|
|
4216
|
+
});
|
|
4194
4217
|
this.LavalinkManager.emit("trackError", this, this.queue.current, error);
|
|
4195
4218
|
if (options && "clientTrack" in options) delete options.clientTrack;
|
|
4196
4219
|
if (options && "track" in options) delete options.track;
|
|
@@ -4251,13 +4274,11 @@ var Player = class {
|
|
|
4251
4274
|
), 1e3), 0));
|
|
4252
4275
|
const now = performance.now();
|
|
4253
4276
|
if (this.LavalinkManager.options.playerOptions.applyVolumeAsFilter) {
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
});
|
|
4260
|
-
}
|
|
4277
|
+
this._emitDebugEvent("PlayerVolumeAsFilter" /* PlayerVolumeAsFilter */, {
|
|
4278
|
+
state: "log",
|
|
4279
|
+
message: `Player Volume was set as a Filter, because LavalinkManager option "playerOptions.applyVolumeAsFilter" is true`,
|
|
4280
|
+
functionLayer: "Player > setVolume()"
|
|
4281
|
+
});
|
|
4261
4282
|
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { filters: { volume: this.lavalinkVolume / 100 } } });
|
|
4262
4283
|
} else {
|
|
4263
4284
|
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { volume: this.lavalinkVolume } });
|
|
@@ -4302,13 +4323,11 @@ var Player = class {
|
|
|
4302
4323
|
async search(query, requestUser, throwOnEmpty = false) {
|
|
4303
4324
|
const Query = this.LavalinkManager.utils.transformQuery(query);
|
|
4304
4325
|
if (["bcsearch", "bandcamp"].includes(Query.source) && !this.node.info?.sourceManagers.includes("bandcamp")) {
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
});
|
|
4311
|
-
}
|
|
4326
|
+
this._emitDebugEvent("BandcampSearchLokalEngine" /* BandcampSearchLokalEngine */, {
|
|
4327
|
+
state: "log",
|
|
4328
|
+
message: `Player.search was called with a Bandcamp Query, but no bandcamp search was enabled on lavalink, searching with the custom Search Engine.`,
|
|
4329
|
+
functionLayer: "Player > search()"
|
|
4330
|
+
});
|
|
4312
4331
|
return await bandCampSearch(this, Query.query, requestUser);
|
|
4313
4332
|
}
|
|
4314
4333
|
return this.node.search(Query, requestUser, throwOnEmpty);
|
|
@@ -4460,13 +4479,11 @@ var Player = class {
|
|
|
4460
4479
|
this.set("internal_queueempty", void 0);
|
|
4461
4480
|
}
|
|
4462
4481
|
if (this.get("internal_destroystatus") === true) {
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
});
|
|
4469
|
-
}
|
|
4482
|
+
this._emitDebugEvent("PlayerDestroyingSomewhereElse" /* PlayerDestroyingSomewhereElse */, {
|
|
4483
|
+
state: "warn",
|
|
4484
|
+
message: `Player is already destroying somewhere else..`,
|
|
4485
|
+
functionLayer: "Player > destroy()"
|
|
4486
|
+
});
|
|
4470
4487
|
if (this.LavalinkManager.options.advancedOptions?.debugOptions.playerDestroy.debugLog) console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Already destroying somewhere else..`);
|
|
4471
4488
|
return;
|
|
4472
4489
|
}
|
|
@@ -4559,17 +4576,15 @@ var Player = class {
|
|
|
4559
4576
|
const missingSources = [...trackSources].filter(
|
|
4560
4577
|
(source) => !updateNode.info?.sourceManagers.includes(source)
|
|
4561
4578
|
);
|
|
4562
|
-
if (missingSources.length)
|
|
4579
|
+
if (this.LavalinkManager.options.autoChecks?.sourcesValidations && missingSources.length)
|
|
4563
4580
|
throw new RangeError(`Sources missing for Node ${updateNode.id}: ${missingSources.join(", ")}`);
|
|
4564
4581
|
}
|
|
4565
4582
|
}
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
});
|
|
4572
|
-
}
|
|
4583
|
+
this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
|
|
4584
|
+
state: "log",
|
|
4585
|
+
message: `Player.changeNode() was executed, trying to change from "${this.node.id}" to "${updateNode.id}"`,
|
|
4586
|
+
functionLayer: "Player > changeNode()"
|
|
4587
|
+
});
|
|
4573
4588
|
const data = this.toJSON();
|
|
4574
4589
|
const currentTrack = this.queue.current;
|
|
4575
4590
|
if (!this.voice.endpoint || !this.voice.sessionId || !this.voice.token)
|
|
@@ -4580,30 +4595,26 @@ var Player = class {
|
|
|
4580
4595
|
const now = performance.now();
|
|
4581
4596
|
try {
|
|
4582
4597
|
await this.connect();
|
|
4583
|
-
const hasSponsorBlock = this.node.info?.plugins?.find((v) => v.name === "sponsorblock-plugin");
|
|
4598
|
+
const hasSponsorBlock = !this.LavalinkManager.options?.autoChecks?.pluginValidations || this.node.info?.plugins?.find((v) => v.name === "sponsorblock-plugin");
|
|
4584
4599
|
if (hasSponsorBlock) {
|
|
4585
4600
|
const sponsorBlockCategories = this.get("internal_sponsorBlockCategories");
|
|
4586
4601
|
if (Array.isArray(sponsorBlockCategories) && sponsorBlockCategories.length) {
|
|
4587
4602
|
await this.setSponsorBlock(sponsorBlockCategories).catch((error) => {
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
});
|
|
4595
|
-
}
|
|
4603
|
+
this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
|
|
4604
|
+
state: "error",
|
|
4605
|
+
error,
|
|
4606
|
+
message: `Player > changeNode() Unable to set SponsorBlock Segments`,
|
|
4607
|
+
functionLayer: "Player > changeNode()"
|
|
4608
|
+
});
|
|
4596
4609
|
});
|
|
4597
4610
|
} else {
|
|
4598
4611
|
await this.setSponsorBlock().catch((error) => {
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
});
|
|
4606
|
-
}
|
|
4612
|
+
this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
|
|
4613
|
+
state: "error",
|
|
4614
|
+
error,
|
|
4615
|
+
message: `Player > changeNode() Unable to set SponsorBlock Segments`,
|
|
4616
|
+
functionLayer: "Player > changeNode()"
|
|
4617
|
+
});
|
|
4607
4618
|
});
|
|
4608
4619
|
}
|
|
4609
4620
|
}
|
|
@@ -4628,14 +4639,12 @@ var Player = class {
|
|
|
4628
4639
|
this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
|
|
4629
4640
|
return this.node.id;
|
|
4630
4641
|
} catch (error) {
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
});
|
|
4638
|
-
}
|
|
4642
|
+
this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
|
|
4643
|
+
state: "error",
|
|
4644
|
+
error,
|
|
4645
|
+
message: `Player.changeNode() execution failed`,
|
|
4646
|
+
functionLayer: "Player > changeNode()"
|
|
4647
|
+
});
|
|
4639
4648
|
throw new Error(`Failed to change the node: ${error}`);
|
|
4640
4649
|
} finally {
|
|
4641
4650
|
this.set("internal_nodeChanging", void 0);
|
|
@@ -4761,6 +4770,10 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
4761
4770
|
id: options?.client?.id,
|
|
4762
4771
|
username: options?.client?.username ?? "lavalink-client"
|
|
4763
4772
|
},
|
|
4773
|
+
autoChecks: {
|
|
4774
|
+
sourcesValidations: options?.autoChecks?.sourcesValidations ?? true,
|
|
4775
|
+
pluginValidations: options?.autoChecks?.pluginValidations ?? true
|
|
4776
|
+
},
|
|
4764
4777
|
sendToShard: options?.sendToShard,
|
|
4765
4778
|
autoMove: options?.autoMove ?? false,
|
|
4766
4779
|
nodes: options?.nodes,
|
|
@@ -4824,6 +4837,8 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
4824
4837
|
if (options?.autoSkipOnResolveError && typeof options?.autoSkipOnResolveError !== "boolean") throw new SyntaxError("ManagerOption.autoSkipOnResolveError must be either false | true aka boolean");
|
|
4825
4838
|
if (options?.emitNewSongsOnly && typeof options?.emitNewSongsOnly !== "boolean") throw new SyntaxError("ManagerOption.emitNewSongsOnly must be either false | true aka boolean");
|
|
4826
4839
|
if (!options?.nodes || !Array.isArray(options?.nodes) || !options?.nodes.every((node) => this.utils.isNodeOptions(node))) throw new SyntaxError("ManagerOption.nodes must be an Array of NodeOptions and is required of at least 1 Node");
|
|
4840
|
+
if (typeof options?.autoChecks?.sourcesValidations !== "boolean") throw new SyntaxError("ManagerOption.autoChecks.sourcesValidations must be either false | true aka boolean");
|
|
4841
|
+
if (typeof options?.autoChecks?.pluginValidations !== "boolean") throw new SyntaxError("ManagerOption.autoChecks.pluginValidations must be either false | true aka boolean");
|
|
4827
4842
|
if (options?.queueOptions?.queueStore) {
|
|
4828
4843
|
const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(options?.queueOptions?.queueStore));
|
|
4829
4844
|
const requiredKeys = ["get", "set", "stringify", "parse", "delete"];
|
|
@@ -4836,6 +4851,15 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
4836
4851
|
}
|
|
4837
4852
|
if (typeof options?.queueOptions?.maxPreviousTracks !== "number" || options?.queueOptions?.maxPreviousTracks < 0) options.queueOptions.maxPreviousTracks = 25;
|
|
4838
4853
|
}
|
|
4854
|
+
/**
|
|
4855
|
+
* Emits a debug event to the LavalinkManager
|
|
4856
|
+
* @param name name of the event
|
|
4857
|
+
* @param eventData event data
|
|
4858
|
+
*/
|
|
4859
|
+
_emitDebugEvent(name, eventData) {
|
|
4860
|
+
if (!this.options?.advancedOptions?.enableDebugEvents) return;
|
|
4861
|
+
this.emit("debug", name, eventData);
|
|
4862
|
+
}
|
|
4839
4863
|
/**
|
|
4840
4864
|
* Create the Lavalink Manager
|
|
4841
4865
|
* @param options
|
|
@@ -4985,13 +5009,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
4985
5009
|
if (!oldPlayer) return;
|
|
4986
5010
|
if (typeof oldPlayer.voiceChannelId === "string" && oldPlayer.connected && !oldPlayer.get("internal_destroywithoutdisconnect")) {
|
|
4987
5011
|
if (!this.options?.advancedOptions?.debugOptions?.playerDestroy?.dontThrowError) throw new Error(`Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player ${safeStringify(oldPlayer.toJSON?.())}`);
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
});
|
|
4994
|
-
}
|
|
5012
|
+
this._emitDebugEvent("PlayerDeleteInsteadOfDestroy" /* PlayerDeleteInsteadOfDestroy */, {
|
|
5013
|
+
state: "warn",
|
|
5014
|
+
message: "Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player",
|
|
5015
|
+
functionLayer: "LavalinkManager > deletePlayer()"
|
|
5016
|
+
});
|
|
4995
5017
|
}
|
|
4996
5018
|
return this.players.delete(guildId);
|
|
4997
5019
|
}
|
|
@@ -5039,13 +5061,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5039
5061
|
}
|
|
5040
5062
|
}
|
|
5041
5063
|
if (success > 0) this.initiated = true;
|
|
5042
|
-
else
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
});
|
|
5048
|
-
}
|
|
5064
|
+
else this._emitDebugEvent("FailedToConnectToNodes" /* FailedToConnectToNodes */, {
|
|
5065
|
+
state: "error",
|
|
5066
|
+
message: "Failed to connect to at least 1 Node",
|
|
5067
|
+
functionLayer: "LavalinkManager > init()"
|
|
5068
|
+
});
|
|
5049
5069
|
return this;
|
|
5050
5070
|
}
|
|
5051
5071
|
/**
|
|
@@ -5065,24 +5085,20 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5065
5085
|
*/
|
|
5066
5086
|
async sendRawData(data) {
|
|
5067
5087
|
if (!this.initiated) {
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
});
|
|
5074
|
-
}
|
|
5088
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5089
|
+
state: "log",
|
|
5090
|
+
message: "Manager is not initated yet",
|
|
5091
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5092
|
+
});
|
|
5075
5093
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, manager is not initated yet");
|
|
5076
5094
|
return;
|
|
5077
5095
|
}
|
|
5078
5096
|
if (!("t" in data)) {
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
});
|
|
5085
|
-
}
|
|
5097
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5098
|
+
state: "error",
|
|
5099
|
+
message: "No 't' in payload-data of the raw event:",
|
|
5100
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5101
|
+
});
|
|
5086
5102
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 't' in payload-data of the raw event:", data);
|
|
5087
5103
|
return;
|
|
5088
5104
|
}
|
|
@@ -5095,47 +5111,39 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5095
5111
|
if (["VOICE_STATE_UPDATE", "VOICE_SERVER_UPDATE"].includes(data.t)) {
|
|
5096
5112
|
const update = "d" in data ? data.d : data;
|
|
5097
5113
|
if (!update) {
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
});
|
|
5104
|
-
}
|
|
5114
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5115
|
+
state: "warn",
|
|
5116
|
+
message: `No Update data found in payload :: ${safeStringify(data, 2)}`,
|
|
5117
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5118
|
+
});
|
|
5105
5119
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no update data found in payload:", data);
|
|
5106
5120
|
return;
|
|
5107
5121
|
}
|
|
5108
5122
|
if (!("token" in update) && !("session_id" in update)) {
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
});
|
|
5115
|
-
}
|
|
5123
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5124
|
+
state: "error",
|
|
5125
|
+
message: `No 'token' nor 'session_id' found in payload :: ${safeStringify(data, 2)}`,
|
|
5126
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5127
|
+
});
|
|
5116
5128
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 'token' nor 'session_id' found in payload:", data);
|
|
5117
5129
|
return;
|
|
5118
5130
|
}
|
|
5119
5131
|
const player = this.getPlayer(update.guild_id);
|
|
5120
5132
|
if (!player) {
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
});
|
|
5127
|
-
}
|
|
5133
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5134
|
+
state: "warn",
|
|
5135
|
+
message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${safeStringify(update, 2)}`,
|
|
5136
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5137
|
+
});
|
|
5128
5138
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, No Lavalink Player found via key: 'guild_id' of update-data:", update);
|
|
5129
5139
|
return;
|
|
5130
5140
|
}
|
|
5131
5141
|
if (player.get("internal_destroystatus") === true) {
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
});
|
|
5138
|
-
}
|
|
5142
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5143
|
+
state: "warn",
|
|
5144
|
+
message: `Player is in a destroying state. can't signal the voice states`,
|
|
5145
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5146
|
+
});
|
|
5139
5147
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Player is in a destroying state. can't signal the voice states");
|
|
5140
5148
|
return;
|
|
5141
5149
|
}
|
|
@@ -5160,13 +5168,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5160
5168
|
}
|
|
5161
5169
|
}
|
|
5162
5170
|
});
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
});
|
|
5169
|
-
}
|
|
5171
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5172
|
+
state: "log",
|
|
5173
|
+
message: `Sent updatePlayer for voice token session :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use }, update, playerVoice: player.voice }, 2)}`,
|
|
5174
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5175
|
+
});
|
|
5170
5176
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use }, playerVoice: player.voice, update });
|
|
5171
5177
|
}
|
|
5172
5178
|
return;
|
|
@@ -5175,13 +5181,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5175
5181
|
if (update.user_id && player.voiceChannelId) {
|
|
5176
5182
|
this.emit(update.channel_id === player.voiceChannelId ? "playerVoiceJoin" : "playerVoiceLeave", player, update.user_id);
|
|
5177
5183
|
}
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
});
|
|
5184
|
-
}
|
|
5184
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5185
|
+
state: "warn",
|
|
5186
|
+
message: `voice update user is not equal to provided client id of the LavalinkManager.options.client.id :: user: "${update.user_id}" manager client id: "${this.options?.client.id}"`,
|
|
5187
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5188
|
+
});
|
|
5185
5189
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, voice update user is not equal to provided client id of the manageroptions#client#id", "user:", update.user_id, "manager client id:", this.options?.client.id);
|
|
5186
5190
|
return;
|
|
5187
5191
|
}
|
|
@@ -5189,13 +5193,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5189
5193
|
if (player.voiceChannelId !== update.channel_id) this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
|
|
5190
5194
|
player.voice.sessionId = update.session_id || player.voice.sessionId;
|
|
5191
5195
|
if (!player.voice.sessionId) {
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
});
|
|
5198
|
-
}
|
|
5196
|
+
this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
|
|
5197
|
+
state: "warn",
|
|
5198
|
+
message: `Function to assing sessionId provided, but no found in Payload: ${safeStringify({ update, playerVoice: player.voice }, 2)}`,
|
|
5199
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5200
|
+
});
|
|
5199
5201
|
if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug(`Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Function to assing sessionId provided, but no found in Payload: ${safeStringify(update, 2)}`);
|
|
5200
5202
|
}
|
|
5201
5203
|
player.voiceChannelId = update.channel_id;
|
|
@@ -5226,13 +5228,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5226
5228
|
try {
|
|
5227
5229
|
const previousPosition = player.position;
|
|
5228
5230
|
const previousPaused = player.paused;
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
});
|
|
5235
|
-
}
|
|
5231
|
+
this._emitDebugEvent("PlayerAutoReconnect" /* PlayerAutoReconnect */, {
|
|
5232
|
+
state: "log",
|
|
5233
|
+
message: `Auto reconnecting player because LavalinkManager.options.playerOptions.onDisconnect.autoReconnect is true`,
|
|
5234
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5235
|
+
});
|
|
5236
5236
|
if (!autoReconnectOnlyWithTracks || autoReconnectOnlyWithTracks && (player.queue.current || player.queue.tracks.length)) {
|
|
5237
5237
|
await player.connect();
|
|
5238
5238
|
}
|
|
@@ -5242,13 +5242,11 @@ var LavalinkManager = class extends import_events2.EventEmitter {
|
|
|
5242
5242
|
if (player.queue.tracks.length) {
|
|
5243
5243
|
return void await player.play({ paused: previousPaused });
|
|
5244
5244
|
}
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
});
|
|
5251
|
-
}
|
|
5245
|
+
this._emitDebugEvent("PlayerAutoReconnect" /* PlayerAutoReconnect */, {
|
|
5246
|
+
state: "log",
|
|
5247
|
+
message: `Auto reconnected, but nothing to play`,
|
|
5248
|
+
functionLayer: "LavalinkManager > sendRawData()"
|
|
5249
|
+
});
|
|
5252
5250
|
return;
|
|
5253
5251
|
} catch (e) {
|
|
5254
5252
|
console.error(e);
|