lavalink-client 2.7.3 → 2.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -44,6 +44,9 @@ var DebugEvents = /* @__PURE__ */ ((DebugEvents2) => {
44
44
  DebugEvents2["FailedToConnectToNodes"] = "FailedToConnectToNodes";
45
45
  DebugEvents2["NoAudioDebug"] = "NoAudioDebug";
46
46
  DebugEvents2["PlayerAutoReconnect"] = "PlayerAutoReconnect";
47
+ DebugEvents2["PlayerDestroyFail"] = "PlayerDestroyFail";
48
+ DebugEvents2["PlayerChangeNodeFailNoEligibleNode"] = "PlayerChangeNodeFailNoEligibleNode";
49
+ DebugEvents2["PlayerChangeNodeFail"] = "PlayerChangeNodeFail";
47
50
  return DebugEvents2;
48
51
  })(DebugEvents || {});
49
52
  var DestroyReasons = /* @__PURE__ */ ((DestroyReasons2) => {
@@ -687,7 +690,7 @@ var ManagerUtils = class {
687
690
  }
688
691
  validateQueryString(node, queryString, sourceString) {
689
692
  if (!node.info) throw new Error("No Lavalink Node was provided");
690
- if (!node.info.sourceManagers?.length) throw new Error("Lavalink Node, has no sourceManagers enabled");
693
+ if (this.LavalinkManager.options?.autoChecks?.sourcesValidations && !node.info.sourceManagers?.length) throw new Error("Lavalink Node, has no sourceManagers enabled");
691
694
  if (!queryString.trim().length) throw new Error(`Query string is empty, please provide a valid query string.`);
692
695
  if (sourceString === "speak" && queryString.length > 100) throw new Error(`Query is speak, which is limited to 100 characters.`);
693
696
  if (this.LavalinkManager.options?.linksBlacklist?.length > 0) {
@@ -716,6 +719,7 @@ var ManagerUtils = class {
716
719
  throw new Error(`Query string contains a link / word which isn't whitelisted.`);
717
720
  }
718
721
  }
722
+ if (!this.LavalinkManager.options?.autoChecks?.sourcesValidations) return;
719
723
  if ((SourceLinksRegexes.YoutubeMusicRegex.test(queryString) || SourceLinksRegexes.YoutubeRegex.test(queryString)) && !node.info?.sourceManagers?.includes("youtube")) {
720
724
  throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'youtube' enabled");
721
725
  }
@@ -799,6 +803,7 @@ var ManagerUtils = class {
799
803
  const source = DefaultSources[sourceString.toLowerCase().trim()];
800
804
  if (!source) throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
801
805
  if (!node.info) throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
806
+ if (!this.LavalinkManager.options?.autoChecks?.sourcesValidations) return;
802
807
  if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
803
808
  throw new Error("Lavalink Node has not 'applemusic' enabled, which is required to have 'amsearch' work");
804
809
  }
@@ -820,7 +825,7 @@ var ManagerUtils = class {
820
825
  if (source === "scsearch" && !node.info?.sourceManagers?.includes("soundcloud")) {
821
826
  throw new Error("Lavalink Node has not 'soundcloud' enabled, which is required to have 'scsearch' work");
822
827
  }
823
- if (source === "speak" && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
828
+ if (source === "speak" && this.LavalinkManager.options?.autoChecks?.pluginValidations && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
824
829
  throw new Error("Lavalink Node has not 'speak' enabled, which is required to have 'speak' work");
825
830
  }
826
831
  if (source === "tdsearch" && !node.info?.sourceManagers?.includes("tidal")) {
@@ -829,7 +834,7 @@ var ManagerUtils = class {
829
834
  if (source === "tdrec" && !node.info?.sourceManagers?.includes("tidal")) {
830
835
  throw new Error("Lavalink Node has not 'tidal' enabled, which is required to have 'tdrec' work");
831
836
  }
832
- if (source === "tts" && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
837
+ if (source === "tts" && this.LavalinkManager.options?.autoChecks?.pluginValidations && !node.info?.plugins?.find((c) => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
833
838
  throw new Error("Lavalink Node has not 'tts' enabled, which is required to have 'tts' work");
834
839
  }
835
840
  if (source === "ftts" && !(node.info?.sourceManagers?.includes("ftts") || node.info?.sourceManagers?.includes("flowery-tts") || node.info?.sourceManagers?.includes("flowerytts"))) {
@@ -838,7 +843,7 @@ var ManagerUtils = class {
838
843
  if (source === "ymsearch" && !node.info?.sourceManagers?.includes("yandexmusic")) {
839
844
  throw new Error("Lavalink Node has not 'yandexmusic' enabled, which is required to have 'ymsearch' work");
840
845
  }
841
- if (source === "ytmsearch" && !node.info.sourceManagers?.includes("youtube")) {
846
+ if (source === "ytmsearch" && !node.info?.sourceManagers?.includes("youtube")) {
842
847
  throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytmsearch' work");
843
848
  }
844
849
  if (source === "ytsearch" && !node.info?.sourceManagers?.includes("youtube")) {
@@ -981,9 +986,6 @@ function safeStringify(obj, padding = 0) {
981
986
  var LavalinkNode = class {
982
987
  heartBeatPingTimestamp = 0;
983
988
  heartBeatPongTimestamp = 0;
984
- get heartBeatPing() {
985
- return this.heartBeatPongTimestamp - this.heartBeatPingTimestamp;
986
- }
987
989
  heartBeatInterval;
988
990
  pingTimeout;
989
991
  isAlive = false;
@@ -1031,6 +1033,68 @@ var LavalinkNode = class {
1031
1033
  socket = null;
1032
1034
  /** Version of what the Lavalink Server should be */
1033
1035
  version = "v4";
1036
+ /**
1037
+ * Returns the LavalinkManager of the Node
1038
+ */
1039
+ get _LManager() {
1040
+ return this.NodeManager.LavalinkManager;
1041
+ }
1042
+ /**
1043
+ * Returns the Heartbeat Ping of the Node
1044
+ */
1045
+ get heartBeatPing() {
1046
+ return this.heartBeatPongTimestamp - this.heartBeatPingTimestamp;
1047
+ }
1048
+ /**
1049
+ * Returns wether the plugin validations are enabled or not
1050
+ */
1051
+ get _checkForPlugins() {
1052
+ return !!this._LManager.options?.autoChecks?.pluginValidations;
1053
+ }
1054
+ /**
1055
+ * Returns wether the source validations are enabled or not
1056
+ */
1057
+ get _checkForSources() {
1058
+ return !!this._LManager.options?.autoChecks?.sourcesValidations;
1059
+ }
1060
+ /**
1061
+ * Emits a debug event to the LavalinkManager
1062
+ * @param name name of the event
1063
+ * @param eventData event data
1064
+ */
1065
+ _emitDebugEvent(name, eventData) {
1066
+ if (!this._LManager.options?.advancedOptions?.enableDebugEvents) return;
1067
+ this._LManager.emit("debug", name, eventData);
1068
+ }
1069
+ /**
1070
+ * Returns if connected to the Node.
1071
+ *
1072
+ * @example
1073
+ * ```ts
1074
+ * const isConnected = player.node.connected;
1075
+ * console.log("node is connected: ", isConnected ? "yes" : "no")
1076
+ * ```
1077
+ */
1078
+ get connected() {
1079
+ return this.socket && this.socket.readyState === WebSocket.OPEN;
1080
+ }
1081
+ /**
1082
+ * Returns the current ConnectionStatus
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * try {
1087
+ * const statusOfConnection = player.node.connectionStatus;
1088
+ * console.log("node's connection status is:", statusOfConnection)
1089
+ * } catch (error) {
1090
+ * console.error("no socket available?", error)
1091
+ * }
1092
+ * ```
1093
+ */
1094
+ get connectionStatus() {
1095
+ if (!this.socket) throw new Error("no websocket was initialized yet");
1096
+ return ["CONNECTING", "OPEN", "CLOSING", "CLOSED"][this.socket.readyState] || "UNKNOWN";
1097
+ }
1034
1098
  /**
1035
1099
  * Create a new Node
1036
1100
  * @param options Lavalink Node Options
@@ -1120,10 +1184,10 @@ var LavalinkNode = class {
1120
1184
  * ```
1121
1185
  */
1122
1186
  async search(query, requestUser, throwOnEmpty = false) {
1123
- const Query = this.NodeManager.LavalinkManager.utils.transformQuery(query);
1124
- this.NodeManager.LavalinkManager.utils.validateQueryString(this, Query.query, Query.source);
1125
- if (Query.source) this.NodeManager.LavalinkManager.utils.validateSourceString(this, Query.source);
1126
- if (["bcsearch", "bandcamp"].includes(Query.source) && !this.info.sourceManagers.includes("bandcamp")) {
1187
+ const Query = this._LManager.utils.transformQuery(query);
1188
+ this._LManager.utils.validateQueryString(this, Query.query, Query.source);
1189
+ if (Query.source) this._LManager.utils.validateSourceString(this, Query.source);
1190
+ if (["bcsearch", "bandcamp"].includes(Query.source) && this._LManager.options?.autoChecks?.sourcesValidations && !this.info.sourceManagers.includes("bandcamp")) {
1127
1191
  throw new Error("Bandcamp Search only works on the player (lavaplayer version < 2.2.0!");
1128
1192
  }
1129
1193
  const requestUrl = new URL(`${this.restAddress}/loadtracks`);
@@ -1142,13 +1206,11 @@ var LavalinkNode = class {
1142
1206
  });
1143
1207
  const resTracks = res.loadType === "playlist" ? res.data?.tracks : res.loadType === "track" ? [res.data] : res.loadType === "search" ? Array.isArray(res.data) ? res.data : [res.data] : [];
1144
1208
  if (throwOnEmpty === true && (res.loadType === "empty" || !resTracks.length)) {
1145
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1146
- this.NodeManager.LavalinkManager.emit("debug", "SearchNothingFound" /* SearchNothingFound */, {
1147
- state: "warn",
1148
- message: `Search found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
1149
- functionLayer: "(LavalinkNode > node | player) > search()"
1150
- });
1151
- }
1209
+ this._emitDebugEvent("SearchNothingFound" /* SearchNothingFound */, {
1210
+ state: "warn",
1211
+ message: `Search found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
1212
+ functionLayer: "(LavalinkNode > node | player) > search()"
1213
+ });
1152
1214
  throw new Error("Nothing found");
1153
1215
  }
1154
1216
  return {
@@ -1161,10 +1223,10 @@ var LavalinkNode = class {
1161
1223
  author: res.data.info?.author || res.data.pluginInfo?.author || null,
1162
1224
  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,
1163
1225
  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,
1164
- selectedTrack: typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1 ? null : resTracks[res.data?.info?.selectedTrack] ? this.NodeManager.LavalinkManager.utils.buildTrack(resTracks[res.data?.info?.selectedTrack], requestUser) : null,
1226
+ 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,
1165
1227
  duration: resTracks.length ? resTracks.reduce((acc, cur) => acc + (cur?.info?.duration || cur?.info?.length || 0), 0) : 0
1166
1228
  } : null,
1167
- tracks: resTracks.length ? resTracks.map((t) => this.NodeManager.LavalinkManager.utils.buildTrack(t, requestUser)) : []
1229
+ tracks: resTracks.length ? resTracks.map((t) => this._LManager.utils.buildTrack(t, requestUser)) : []
1168
1230
  };
1169
1231
  }
1170
1232
  /**
@@ -1181,29 +1243,27 @@ var LavalinkNode = class {
1181
1243
  * ```
1182
1244
  */
1183
1245
  async lavaSearch(query, requestUser, throwOnEmpty = false) {
1184
- const Query = this.NodeManager.LavalinkManager.utils.transformLavaSearchQuery(query);
1185
- if (Query.source) this.NodeManager.LavalinkManager.utils.validateSourceString(this, Query.source);
1246
+ const Query = this._LManager.utils.transformLavaSearchQuery(query);
1247
+ if (Query.source) this._LManager.utils.validateSourceString(this, Query.source);
1186
1248
  if (/^https?:\/\//.test(Query.query)) return this.search({ query: Query.query, source: Query.source }, requestUser);
1187
1249
  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"`);
1188
- if (!this.info.plugins.find((v) => v.name === "lavasearch-plugin")) throw new RangeError(`there is no lavasearch-plugin available in the lavalink node: ${this.id}`);
1189
- if (!this.info.plugins.find((v) => v.name === "lavasrc-plugin")) throw new RangeError(`there is no lavasrc-plugin available in the lavalink node: ${this.id}`);
1250
+ 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}`);
1251
+ 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}`);
1190
1252
  const { response } = await this.rawRequest(`/loadsearch?query=${Query.source ? `${Query.source}:` : ""}${encodeURIComponent(Query.query)}${Query.types?.length ? `&types=${Query.types.join(",")}` : ""}`);
1191
1253
  const res = response.status === 204 ? {} : await response.json();
1192
1254
  if (throwOnEmpty === true && !Object.entries(res).flat().filter(Boolean).length) {
1193
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1194
- this.NodeManager.LavalinkManager.emit("debug", "LavaSearchNothingFound" /* LavaSearchNothingFound */, {
1195
- state: "warn",
1196
- message: `LavaSearch found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
1197
- functionLayer: "(LavalinkNode > node | player) > lavaSearch()"
1198
- });
1199
- }
1255
+ this._emitDebugEvent("LavaSearchNothingFound" /* LavaSearchNothingFound */, {
1256
+ state: "warn",
1257
+ message: `LavaSearch found nothing for Request: "${Query.source ? `${Query.source}:` : ""}${Query.query}"`,
1258
+ functionLayer: "(LavalinkNode > node | player) > lavaSearch()"
1259
+ });
1200
1260
  throw new Error("Nothing found");
1201
1261
  }
1202
1262
  return {
1203
- tracks: res.tracks?.map((v) => this.NodeManager.LavalinkManager.utils.buildTrack(v, requestUser)) || [],
1204
- albums: res.albums?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.NodeManager.LavalinkManager.utils.buildTrack(v2, requestUser)) })) || [],
1205
- artists: res.artists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.NodeManager.LavalinkManager.utils.buildTrack(v2, requestUser)) })) || [],
1206
- playlists: res.playlists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this.NodeManager.LavalinkManager.utils.buildTrack(v2, requestUser)) })) || [],
1263
+ tracks: res.tracks?.map((v) => this._LManager.utils.buildTrack(v, requestUser)) || [],
1264
+ albums: res.albums?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
1265
+ artists: res.artists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
1266
+ playlists: res.playlists?.map((v) => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map((v2) => this._LManager.utils.buildTrack(v2, requestUser)) })) || [],
1207
1267
  texts: res.texts?.map((v) => ({ text: v.text, pluginInfo: v?.plugin || v.pluginInfo })) || [],
1208
1268
  pluginInfo: res.pluginInfo || res?.plugin
1209
1269
  };
@@ -1232,13 +1292,11 @@ var LavalinkNode = class {
1232
1292
  r.path = url.pathname + url.search;
1233
1293
  }
1234
1294
  });
1235
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1236
- this.NodeManager.LavalinkManager.emit("debug", "PlayerUpdateSuccess" /* PlayerUpdateSuccess */, {
1237
- state: "log",
1238
- message: `Player get's updated with following payload :: ${safeStringify(data.playerOptions, 3)}`,
1239
- functionLayer: "LavalinkNode > node > updatePlayer()"
1240
- });
1241
- }
1295
+ this._emitDebugEvent("PlayerUpdateSuccess" /* PlayerUpdateSuccess */, {
1296
+ state: "log",
1297
+ message: `Player get's updated with following payload :: ${safeStringify(data.playerOptions, 3)}`,
1298
+ functionLayer: "LavalinkNode > node > updatePlayer()"
1299
+ });
1242
1300
  this.syncPlayerData({}, res);
1243
1301
  return res;
1244
1302
  }
@@ -1274,19 +1332,17 @@ var LavalinkNode = class {
1274
1332
  */
1275
1333
  connect(sessionId) {
1276
1334
  if (this.connected) {
1277
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1278
- this.NodeManager.LavalinkManager.emit("debug", "TryingConnectWhileConnected" /* TryingConnectWhileConnected */, {
1279
- state: "warn",
1280
- message: `Tryed to connect to node, but it's already connected!`,
1281
- functionLayer: "LavalinkNode > node > connect()"
1282
- });
1283
- }
1335
+ this._emitDebugEvent("TryingConnectWhileConnected" /* TryingConnectWhileConnected */, {
1336
+ state: "warn",
1337
+ message: `Tryed to connect to node, but it's already connected!`,
1338
+ functionLayer: "LavalinkNode > node > connect()"
1339
+ });
1284
1340
  return;
1285
1341
  }
1286
1342
  const headers = {
1287
1343
  Authorization: this.options.authorization,
1288
- "User-Id": this.NodeManager.LavalinkManager.options.client.id,
1289
- "Client-Name": this.NodeManager.LavalinkManager.options.client.username || "Lavalink-Client"
1344
+ "User-Id": this._LManager.options.client.id,
1345
+ "Client-Name": this._LManager.options.client.username || "Lavalink-Client"
1290
1346
  };
1291
1347
  if (typeof this.options.sessionId === "string" || typeof sessionId === "string") {
1292
1348
  headers["Session-Id"] = this.options.sessionId || sessionId;
@@ -1299,34 +1355,27 @@ var LavalinkNode = class {
1299
1355
  this.socket.on("error", this.error.bind(this));
1300
1356
  }
1301
1357
  heartBeat() {
1302
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1303
- this.NodeManager.LavalinkManager.emit("debug", "HeartBeatTriggered" /* HeartBeatTriggered */, {
1304
- state: "log",
1305
- message: `Node Socket Heartbeat triggered, resetting old Timeout to 65000ms (should happen every 60s due to /stats event)`,
1306
- functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat()"
1307
- });
1308
- }
1358
+ this._emitDebugEvent("HeartBeatTriggered" /* HeartBeatTriggered */, {
1359
+ state: "log",
1360
+ message: `Node Socket Heartbeat triggered, resetting old Timeout to 65000ms (should happen every 60s due to /stats event)`,
1361
+ functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat()"
1362
+ });
1309
1363
  this.resetAckTimeouts(false, true);
1310
1364
  if (this.pingTimeout) clearTimeout(this.pingTimeout);
1311
1365
  this.pingTimeout = setTimeout(() => {
1312
1366
  this.pingTimeout = null;
1313
1367
  if (!this.socket) {
1314
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1315
- this.NodeManager.LavalinkManager.emit("debug", "NoSocketOnDestroy" /* NoSocketOnDestroy */, {
1316
- state: "error",
1317
- message: `Heartbeat registered a disconnect, but socket didn't exist therefore can't terminate`,
1318
- functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
1319
- });
1320
- }
1321
- return;
1322
- }
1323
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1324
- this.NodeManager.LavalinkManager.emit("debug", "SocketTerminateHeartBeatTimeout" /* SocketTerminateHeartBeatTimeout */, {
1325
- state: "warn",
1326
- message: `Heartbeat registered a disconnect, because timeout wasn't resetted in time. Terminating Web-Socket`,
1368
+ return this._emitDebugEvent("NoSocketOnDestroy" /* NoSocketOnDestroy */, {
1369
+ state: "error",
1370
+ message: `Heartbeat registered a disconnect, but socket didn't exist therefore can't terminate`,
1327
1371
  functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
1328
1372
  });
1329
1373
  }
1374
+ this._emitDebugEvent("SocketTerminateHeartBeatTimeout" /* SocketTerminateHeartBeatTimeout */, {
1375
+ state: "warn",
1376
+ message: `Heartbeat registered a disconnect, because timeout wasn't resetted in time. Terminating Web-Socket`,
1377
+ functionLayer: "LavalinkNode > nodeEvent > stats > heartBeat() > timeoutHit"
1378
+ });
1330
1379
  this.isAlive = false;
1331
1380
  this.socket.terminate();
1332
1381
  }, 65e3);
@@ -1361,71 +1410,76 @@ var LavalinkNode = class {
1361
1410
  * ```
1362
1411
  */
1363
1412
  destroy(destroyReason, deleteNode = true, movePlayers = false) {
1364
- const players = this.NodeManager.LavalinkManager.players.filter((p) => p.node.id === this.id);
1365
- if (players.size) {
1366
- const enableDebugEvents = this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents;
1367
- const handlePlayerOperations = () => {
1368
- if (movePlayers) {
1369
- const nodeToMove = Array.from(this.NodeManager.leastUsedNodes("playingPlayers")).find((n) => n.connected && n.options.id !== this.id);
1370
- if (nodeToMove) {
1371
- return Promise.allSettled(Array.from(players.values()).map(
1372
- (player) => player.changeNode(nodeToMove.options.id).catch((error) => {
1373
- if (enableDebugEvents) {
1374
- console.error(`Node > destroy() Failed to move player ${player.guildId}: ${error.message}`);
1375
- }
1376
- return player.destroy(error.message ?? "PlayerChangeNodeFail" /* PlayerChangeNodeFail */).catch((destroyError) => {
1377
- if (enableDebugEvents) {
1378
- console.error(`Node > destroy() Failed to destroy player ${player.guildId} after move failure: ${destroyError.message}`);
1379
- }
1380
- });
1381
- })
1382
- ));
1383
- } else {
1384
- return Promise.allSettled(Array.from(players.values()).map(
1385
- (player) => player.destroy("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */).catch((error) => {
1386
- if (enableDebugEvents) {
1387
- console.error(`Node > destroy() Failed to destroy player ${player.guildId}: ${error.message}`);
1388
- }
1389
- })
1390
- ));
1391
- }
1392
- } else {
1393
- return Promise.allSettled(Array.from(players.values()).map(
1394
- (player) => player.destroy(destroyReason || "NodeDestroy" /* NodeDestroy */).catch((error) => {
1395
- if (enableDebugEvents) {
1396
- console.error(`Node > destroy() Failed to destroy player ${player.guildId}: ${error.message}`);
1397
- }
1398
- })
1399
- ));
1400
- }
1401
- };
1402
- handlePlayerOperations().finally(() => {
1403
- this.socket?.close(1e3, "Node-Destroy");
1404
- this.socket?.removeAllListeners();
1405
- this.socket = null;
1406
- this.resetReconnectionAttempts();
1407
- if (deleteNode) {
1408
- this.NodeManager.emit("destroy", this, destroyReason);
1409
- this.NodeManager.nodes.delete(this.id);
1410
- this.resetAckTimeouts(true, true);
1411
- } else {
1412
- this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
1413
- }
1414
- });
1415
- } else {
1413
+ this.reconnectionState = "IDLE" /* IDLE */;
1414
+ const players = this._LManager.players.filter((p) => p.node.id === this.id);
1415
+ if (!players?.size) {
1416
1416
  this.socket?.close(1e3, "Node-Destroy");
1417
1417
  this.socket?.removeAllListeners();
1418
1418
  this.socket = null;
1419
1419
  this.resetReconnectionAttempts();
1420
- if (deleteNode) {
1421
- this.NodeManager.emit("destroy", this, destroyReason);
1422
- this.NodeManager.nodes.delete(this.id);
1423
- this.resetAckTimeouts(true, true);
1424
- } else {
1425
- this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
1426
- }
1420
+ if (!deleteNode) return void this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
1421
+ ;
1422
+ this.NodeManager.emit("destroy", this, destroyReason);
1423
+ this.NodeManager.nodes.delete(this.id);
1424
+ this.resetAckTimeouts(true, true);
1425
+ return;
1427
1426
  }
1428
- return;
1427
+ const handlePlayerOperations = () => {
1428
+ if (!movePlayers) {
1429
+ return Promise.allSettled(Array.from(players.values()).map(
1430
+ (player) => player.destroy(destroyReason || "NodeDestroy" /* NodeDestroy */).catch((error) => {
1431
+ this._emitDebugEvent("PlayerDestroyFail" /* PlayerDestroyFail */, {
1432
+ state: "error",
1433
+ message: `Failed to destroy player ${player.guildId}: ${error.message}`,
1434
+ error,
1435
+ functionLayer: "Node > destroy() > movePlayers"
1436
+ });
1437
+ })
1438
+ ));
1439
+ }
1440
+ const nodeToMove = Array.from(this.NodeManager.leastUsedNodes("playingPlayers")).find((n) => n.connected && n.options.id !== this.id);
1441
+ if (!nodeToMove) {
1442
+ return Promise.allSettled(Array.from(players.values()).map(
1443
+ (player) => player.destroy("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */).catch((error) => {
1444
+ this._emitDebugEvent("PlayerChangeNodeFailNoEligibleNode" /* PlayerChangeNodeFailNoEligibleNode */, {
1445
+ state: "error",
1446
+ message: `Failed to destroy player ${player.guildId}: ${error.message}`,
1447
+ error,
1448
+ functionLayer: "Node > destroy() > movePlayers"
1449
+ });
1450
+ })
1451
+ ));
1452
+ }
1453
+ return Promise.allSettled(Array.from(players.values()).map(
1454
+ (player) => player.changeNode(nodeToMove.options.id).catch((error) => {
1455
+ this._emitDebugEvent("PlayerChangeNodeFail" /* PlayerChangeNodeFail */, {
1456
+ state: "error",
1457
+ message: `Failed to move player ${player.guildId}: ${error.message}`,
1458
+ error,
1459
+ functionLayer: "Node > destroy() > movePlayers"
1460
+ });
1461
+ return player.destroy(error.message ?? "PlayerChangeNodeFail" /* PlayerChangeNodeFail */).catch((destroyError) => {
1462
+ this._emitDebugEvent("PlayerDestroyFail" /* PlayerDestroyFail */, {
1463
+ state: "error",
1464
+ message: `Failed to destroy player ${player.guildId} after move failure: ${destroyError.message}`,
1465
+ error: destroyError,
1466
+ functionLayer: "Node > destroy() > movePlayers"
1467
+ });
1468
+ });
1469
+ })
1470
+ ));
1471
+ };
1472
+ return void handlePlayerOperations().finally(() => {
1473
+ this.socket?.close(1e3, "Node-Destroy");
1474
+ this.socket?.removeAllListeners();
1475
+ this.socket = null;
1476
+ this.resetReconnectionAttempts();
1477
+ if (!deleteNode) return void this.NodeManager.emit("disconnect", this, { code: 1e3, reason: destroyReason });
1478
+ this.NodeManager.emit("destroy", this, destroyReason);
1479
+ this.NodeManager.nodes.delete(this.id);
1480
+ this.resetAckTimeouts(true, true);
1481
+ return;
1482
+ });
1429
1483
  }
1430
1484
  /**
1431
1485
  * Disconnects the Node-Connection (Websocket)
@@ -1436,7 +1490,7 @@ var LavalinkNode = class {
1436
1490
  *
1437
1491
  * @example
1438
1492
  * ```ts
1439
- * player.node.destroy("custom Player Destroy Reason", true);
1493
+ * player.node.disconnect("Forcefully disconnect the connection to the node.");
1440
1494
  * ```
1441
1495
  */
1442
1496
  disconnect(disconnectReason) {
@@ -1444,38 +1498,10 @@ var LavalinkNode = class {
1444
1498
  this.socket?.close(1e3, "Node-Disconnect");
1445
1499
  this.socket?.removeAllListeners();
1446
1500
  this.socket = null;
1501
+ this.reconnectionState = "IDLE" /* IDLE */;
1447
1502
  this.resetReconnectionAttempts();
1448
1503
  this.NodeManager.emit("disconnect", this, { code: 1e3, reason: disconnectReason });
1449
1504
  }
1450
- /**
1451
- * Returns if connected to the Node.
1452
- *
1453
- * @example
1454
- * ```ts
1455
- * const isConnected = player.node.connected;
1456
- * console.log("node is connected: ", isConnected ? "yes" : "no")
1457
- * ```
1458
- */
1459
- get connected() {
1460
- return this.socket && this.socket.readyState === WebSocket.OPEN;
1461
- }
1462
- /**
1463
- * Returns the current ConnectionStatus
1464
- *
1465
- * @example
1466
- * ```ts
1467
- * try {
1468
- * const statusOfConnection = player.node.connectionStatus;
1469
- * console.log("node's connection status is:", statusOfConnection)
1470
- * } catch (error) {
1471
- * console.error("no socket available?", error)
1472
- * }
1473
- * ```
1474
- */
1475
- get connectionStatus() {
1476
- if (!this.socket) throw new Error("no websocket was initialized yet");
1477
- return ["CONNECTING", "OPEN", "CLOSING", "CLOSED"][this.socket.readyState] || "UNKNOWN";
1478
- }
1479
1505
  /**
1480
1506
  * Gets all Players of a Node
1481
1507
  * @returns array of players inside of lavalink
@@ -1549,7 +1575,7 @@ var LavalinkNode = class {
1549
1575
  */
1550
1576
  singleTrack: async (encoded, requester) => {
1551
1577
  if (!encoded) throw new SyntaxError("No encoded (Base64 string) was provided");
1552
- return this.NodeManager.LavalinkManager.utils?.buildTrack(await this.request(`/decodetrack?encodedTrack=${encodeURIComponent(encoded.replace(/\s/g, ""))}`), requester);
1578
+ return this._LManager.utils?.buildTrack(await this.request(`/decodetrack?encodedTrack=${encodeURIComponent(encoded.replace(/\s/g, ""))}`), requester);
1553
1579
  },
1554
1580
  /**
1555
1581
  * Decodes multiple tracks into their info
@@ -1570,7 +1596,7 @@ var LavalinkNode = class {
1570
1596
  r.method = "POST";
1571
1597
  r.body = safeStringify(encodeds);
1572
1598
  r.headers["Content-Type"] = "application/json";
1573
- }).then((r) => r.map((track) => this.NodeManager.LavalinkManager.utils.buildTrack(track, requester)));
1599
+ }).then((r) => r.map((track) => this._LManager.utils.buildTrack(track, requester)));
1574
1600
  }
1575
1601
  };
1576
1602
  lyrics = {
@@ -1589,8 +1615,8 @@ var LavalinkNode = class {
1589
1615
  */
1590
1616
  get: async (track, skipTrackSource = false) => {
1591
1617
  if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
1592
- if (!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}`);
1593
- if (!this.info.plugins.find((v) => v.name === "lavasrc-plugin") && !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}`);
1618
+ 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}`);
1619
+ 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}`);
1594
1620
  const url = `/lyrics?track=${track.encoded}&skipTrackSource=${skipTrackSource}`;
1595
1621
  return await this.request(url);
1596
1622
  },
@@ -1609,8 +1635,8 @@ var LavalinkNode = class {
1609
1635
  */
1610
1636
  getCurrent: async (guildId, skipTrackSource = false) => {
1611
1637
  if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
1612
- if (!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}`);
1613
- if (!this.info.plugins.find((v) => v.name === "lavasrc-plugin") && !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}`);
1638
+ 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}`);
1639
+ 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}`);
1614
1640
  const url = `/sessions/${this.sessionId}/players/${guildId}/track/lyrics?skipTrackSource=${skipTrackSource}`;
1615
1641
  return await this.request(url);
1616
1642
  },
@@ -1628,7 +1654,7 @@ var LavalinkNode = class {
1628
1654
  */
1629
1655
  subscribe: async (guildId) => {
1630
1656
  if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
1631
- if (!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}`);
1657
+ 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}`);
1632
1658
  return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/subscribe`, (options) => {
1633
1659
  options.method = "POST";
1634
1660
  });
@@ -1647,7 +1673,7 @@ var LavalinkNode = class {
1647
1673
  */
1648
1674
  unsubscribe: async (guildId) => {
1649
1675
  if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
1650
- if (!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}`);
1676
+ 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}`);
1651
1677
  return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/subscribe`, (options) => {
1652
1678
  options.method = "DELETE";
1653
1679
  });
@@ -1761,7 +1787,7 @@ var LavalinkNode = class {
1761
1787
  */
1762
1788
  syncPlayerData(data, res) {
1763
1789
  if (typeof data === "object" && typeof data?.guildId === "string" && typeof data.playerOptions === "object" && Object.keys(data.playerOptions).length > 0) {
1764
- const player = this.NodeManager.LavalinkManager.getPlayer(data.guildId);
1790
+ const player = this._LManager.getPlayer(data.guildId);
1765
1791
  if (!player) return;
1766
1792
  if (typeof data.playerOptions.paused !== "undefined") {
1767
1793
  player.paused = data.playerOptions.paused;
@@ -1773,8 +1799,8 @@ var LavalinkNode = class {
1773
1799
  }
1774
1800
  if (typeof data.playerOptions.voice !== "undefined") player.voice = data.playerOptions.voice;
1775
1801
  if (typeof data.playerOptions.volume !== "undefined") {
1776
- if (this.NodeManager.LavalinkManager.options.playerOptions.volumeDecrementer) {
1777
- player.volume = Math.round(data.playerOptions.volume / this.NodeManager.LavalinkManager.options.playerOptions.volumeDecrementer);
1802
+ if (this._LManager.options.playerOptions.volumeDecrementer) {
1803
+ player.volume = Math.round(data.playerOptions.volume / this._LManager.options.playerOptions.volumeDecrementer);
1778
1804
  player.lavalinkVolume = Math.round(data.playerOptions.volume);
1779
1805
  } else {
1780
1806
  player.volume = Math.round(data.playerOptions.volume);
@@ -1798,7 +1824,7 @@ var LavalinkNode = class {
1798
1824
  }
1799
1825
  }
1800
1826
  if (res?.guildId === "string" && typeof res?.voice !== "undefined") {
1801
- const player = this.NodeManager.LavalinkManager.getPlayer(data.guildId);
1827
+ const player = this._LManager.getPlayer(data.guildId);
1802
1828
  if (!player) return;
1803
1829
  if (typeof res?.voice?.connected === "boolean" && res.voice.connected === false) {
1804
1830
  player.destroy("LavalinkNoVoice" /* LavalinkNoVoice */);
@@ -1908,10 +1934,10 @@ var LavalinkNode = class {
1908
1934
  });
1909
1935
  this.heartBeatInterval = setInterval(() => {
1910
1936
  if (!this.socket) return console.error("Node-Heartbeat-Interval - Socket not available - maybe reconnecting?");
1911
- if (!this.isAlive) this.close(500, "Node-Heartbeat-Timeout");
1937
+ if (!this.isAlive) return this.close(500, "Node-Heartbeat-Timeout");
1912
1938
  this.isAlive = false;
1913
1939
  this.heartBeatPingTimestamp = performance.now();
1914
- this.socket.ping();
1940
+ this.socket?.ping?.();
1915
1941
  }, this.options.heartBeatInterval || 3e4);
1916
1942
  }
1917
1943
  this.info = await this.fetchInfo().catch((e) => (console.error(e, "ON-OPEN-FETCH"), null));
@@ -1931,7 +1957,7 @@ var LavalinkNode = class {
1931
1957
  }
1932
1958
  } catch (e) {
1933
1959
  if (this.NodeManager?.LavalinkManager?.options?.advancedOptions?.enableDebugEvents) {
1934
- this.NodeManager.LavalinkManager.emit("debug", "SocketCleanupError" /* SocketCleanupError */, {
1960
+ this._LManager.emit("debug", "SocketCleanupError" /* SocketCleanupError */, {
1935
1961
  state: "warn",
1936
1962
  message: `An error occurred during socket cleanup in close() (likely a race condition): ${e.message}`,
1937
1963
  functionLayer: "LavalinkNode > close()"
@@ -1947,9 +1973,9 @@ var LavalinkNode = class {
1947
1973
  this.reconnect();
1948
1974
  }
1949
1975
  }
1950
- this.NodeManager.LavalinkManager.players.filter((p) => p?.node?.options?.id === this?.options?.id).forEach((p) => {
1951
- if (!this.NodeManager.LavalinkManager.options.autoMove) return p.playing = false;
1952
- if (this.NodeManager.LavalinkManager.options.autoMove) {
1976
+ this._LManager.players.filter((p) => p?.node?.options?.id === this?.options?.id).forEach((p) => {
1977
+ if (!this._LManager.options.autoMove) return p.playing = false;
1978
+ if (this._LManager.options.autoMove) {
1953
1979
  if (this.NodeManager.nodes.filter((n) => n.connected).size === 0)
1954
1980
  return p.playing = false;
1955
1981
  p.moveNode();
@@ -1960,6 +1986,7 @@ var LavalinkNode = class {
1960
1986
  error(error) {
1961
1987
  if (!error) return;
1962
1988
  this.NodeManager.emit("error", this, error);
1989
+ this.reconnectionState = "IDLE" /* IDLE */;
1963
1990
  this.reconnect();
1964
1991
  if (this.options.closeOnError) {
1965
1992
  if (this.heartBeatInterval) clearInterval(this.heartBeatInterval);
@@ -1989,17 +2016,12 @@ var LavalinkNode = class {
1989
2016
  break;
1990
2017
  case "playerUpdate":
1991
2018
  {
1992
- const player = this.NodeManager.LavalinkManager.getPlayer(payload.guildId);
1993
- if (!player) {
1994
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
1995
- this.NodeManager.LavalinkManager.emit("debug", "PlayerUpdateNoPlayer" /* PlayerUpdateNoPlayer */, {
1996
- state: "error",
1997
- message: `PlayerUpdate Event Triggered, but no player found of payload.guildId: ${payload.guildId}`,
1998
- functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
1999
- });
2000
- }
2001
- return;
2002
- }
2019
+ const player = this._LManager.getPlayer(payload.guildId);
2020
+ if (!player) return this._emitDebugEvent("PlayerUpdateNoPlayer" /* PlayerUpdateNoPlayer */, {
2021
+ state: "error",
2022
+ message: `PlayerUpdate Event Triggered, but no player found of payload.guildId: ${payload.guildId}`,
2023
+ functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
2024
+ });
2003
2025
  const oldPlayer = player?.toJSON();
2004
2026
  player.lastPositionChange = Date.now();
2005
2027
  player.lastPosition = payload.state.position || 0;
@@ -2008,16 +2030,14 @@ var LavalinkNode = class {
2008
2030
  if (!player.createdTimeStamp && payload.state.time) player.createdTimeStamp = payload.state.time;
2009
2031
  if (player.filterManager.filterUpdatedState === true && ((player.queue.current?.info?.duration || 0) <= (player.LavalinkManager.options.advancedOptions.maxFilterFixDuration || 6e5) || player.queue.current?.info?.uri && isAbsolute(player.queue.current?.info?.uri))) {
2010
2032
  player.filterManager.filterUpdatedState = false;
2011
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2012
- this.NodeManager.LavalinkManager.emit("debug", "PlayerUpdateFilterFixApply" /* PlayerUpdateFilterFixApply */, {
2013
- state: "log",
2014
- message: `Fixing FilterState on "${player.guildId}" because player.options.instaUpdateFiltersFix === true`,
2015
- functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
2016
- });
2017
- }
2033
+ this._emitDebugEvent("PlayerUpdateFilterFixApply" /* PlayerUpdateFilterFixApply */, {
2034
+ state: "log",
2035
+ message: `Fixing FilterState on "${player.guildId}" because player.options.instaUpdateFiltersFix === true`,
2036
+ functionLayer: "LavalinkNode > nodeEvent > playerUpdate"
2037
+ });
2018
2038
  await player.seek(player.position);
2019
2039
  }
2020
- this.NodeManager.LavalinkManager.emit("playerUpdate", oldPlayer, player);
2040
+ this._LManager.emit("playerUpdate", oldPlayer, player);
2021
2041
  }
2022
2042
  break;
2023
2043
  case "event":
@@ -2031,14 +2051,12 @@ var LavalinkNode = class {
2031
2051
  try {
2032
2052
  this.NodeManager.emit("resumed", this, payload, await this.fetchAllPlayers());
2033
2053
  } catch (e) {
2034
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2035
- this.NodeManager.LavalinkManager.emit("debug", "ResumingFetchingError" /* ResumingFetchingError */, {
2036
- state: "error",
2037
- message: `Failed to fetch players for resumed event, falling back without players array`,
2038
- error: e,
2039
- functionLayer: "LavalinkNode > nodeEvent > resumed"
2040
- });
2041
- }
2054
+ this._emitDebugEvent("ResumingFetchingError" /* ResumingFetchingError */, {
2055
+ state: "error",
2056
+ message: `Failed to fetch players for resumed event, falling back without players array`,
2057
+ error: e,
2058
+ functionLayer: "LavalinkNode > nodeEvent > resumed"
2059
+ });
2042
2060
  this.NodeManager.emit("resumed", this, payload, []);
2043
2061
  }
2044
2062
  }
@@ -2051,7 +2069,7 @@ var LavalinkNode = class {
2051
2069
  /** @private middleware util function for handling all kind of events from websocket */
2052
2070
  async handleEvent(payload) {
2053
2071
  if (!payload?.guildId) return;
2054
- const player = this.NodeManager.LavalinkManager.getPlayer(payload.guildId);
2072
+ const player = this._LManager.getPlayer(payload.guildId);
2055
2073
  if (!player) return;
2056
2074
  switch (payload.type) {
2057
2075
  case "TrackStartEvent":
@@ -2097,7 +2115,7 @@ var LavalinkNode = class {
2097
2115
  return;
2098
2116
  }
2099
2117
  getTrackOfPayload(payload) {
2100
- return "track" in payload ? this.NodeManager.LavalinkManager.utils.buildTrack(payload.track, void 0) : null;
2118
+ return "track" in payload ? this._LManager.utils.buildTrack(payload.track, void 0) : null;
2101
2119
  }
2102
2120
  /** @private util function for handling trackStart event */
2103
2121
  async trackStart(player, track, payload) {
@@ -2105,31 +2123,26 @@ var LavalinkNode = class {
2105
2123
  player.playing = true;
2106
2124
  player.paused = false;
2107
2125
  }
2108
- if (this.NodeManager.LavalinkManager.options?.emitNewSongsOnly === true && player.queue.previous[0]?.info?.identifier === track?.info?.identifier) {
2109
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2110
- this.NodeManager.LavalinkManager.emit("debug", "TrackStartNewSongsOnly" /* TrackStartNewSongsOnly */, {
2111
- state: "log",
2112
- message: `TrackStart not Emitting, because playing the previous song again.`,
2113
- functionLayer: "LavalinkNode > trackStart()"
2114
- });
2115
- }
2116
- return;
2126
+ if (this._LManager.options?.emitNewSongsOnly === true && player.queue.previous[0]?.info?.identifier === track?.info?.identifier) {
2127
+ return this._emitDebugEvent("TrackStartNewSongsOnly" /* TrackStartNewSongsOnly */, {
2128
+ state: "log",
2129
+ message: `TrackStart not Emitting, because playing the previous song again.`,
2130
+ functionLayer: "LavalinkNode > trackStart()"
2131
+ });
2117
2132
  }
2118
2133
  if (!player.queue.current) {
2119
2134
  player.queue.current = this.getTrackOfPayload(payload);
2120
2135
  if (player.queue.current) {
2121
2136
  await player.queue.utils.save();
2122
2137
  } else {
2123
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2124
- this.NodeManager.LavalinkManager.emit("debug", "TrackStartNoTrack" /* TrackStartNoTrack */, {
2125
- state: "warn",
2126
- message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2127
- functionLayer: "LavalinkNode > trackStart()"
2128
- });
2129
- }
2138
+ this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
2139
+ state: "warn",
2140
+ message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2141
+ functionLayer: "LavalinkNode > trackStart()"
2142
+ });
2130
2143
  }
2131
2144
  }
2132
- this.NodeManager.LavalinkManager.emit("trackStart", player, player.queue.current, payload);
2145
+ this._LManager.emit("trackStart", player, player.queue.current, payload);
2133
2146
  return;
2134
2147
  }
2135
2148
  /** @private util function for handling trackEnd event */
@@ -2137,14 +2150,12 @@ var LavalinkNode = class {
2137
2150
  if (player.get("internal_nodeChanging") === true) return;
2138
2151
  const trackToUse = track || this.getTrackOfPayload(payload);
2139
2152
  if (payload.reason === "replaced") {
2140
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2141
- this.NodeManager.LavalinkManager.emit("debug", "TrackEndReplaced" /* TrackEndReplaced */, {
2142
- state: "warn",
2143
- message: `TrackEnd Event does not handle any playback, because the track was replaced.`,
2144
- functionLayer: "LavalinkNode > trackEnd()"
2145
- });
2146
- }
2147
- this.NodeManager.LavalinkManager.emit("trackEnd", player, trackToUse, payload);
2153
+ this._emitDebugEvent("TrackEndReplaced" /* TrackEndReplaced */, {
2154
+ state: "warn",
2155
+ message: `TrackEnd Event does not handle any playback, because the track was replaced.`,
2156
+ functionLayer: "LavalinkNode > trackEnd()"
2157
+ });
2158
+ this._LManager.emit("trackEnd", player, trackToUse, payload);
2148
2159
  return;
2149
2160
  }
2150
2161
  if (!player.queue.tracks.length && (player.repeatMode === "off" || player.get("internal_stopPlaying"))) return this.queueEnd(player, track, payload);
@@ -2152,8 +2163,8 @@ var LavalinkNode = class {
2152
2163
  if (player.get("internal_destroystatus") === true) return;
2153
2164
  await queueTrackEnd(player);
2154
2165
  if (!player.queue.current) return this.queueEnd(player, trackToUse, payload);
2155
- this.NodeManager.LavalinkManager.emit("trackEnd", player, trackToUse, payload);
2156
- if (this.NodeManager.LavalinkManager.options.autoSkip && player.queue.current) {
2166
+ this._LManager.emit("trackEnd", player, trackToUse, payload);
2167
+ if (this._LManager.options.autoSkip && player.queue.current) {
2157
2168
  player.play({ noReplace: true });
2158
2169
  }
2159
2170
  return;
@@ -2166,30 +2177,28 @@ var LavalinkNode = class {
2166
2177
  }
2167
2178
  if (!player.queue.current) return this.queueEnd(player, trackToUse, payload);
2168
2179
  player.set("internal_skipped", false);
2169
- this.NodeManager.LavalinkManager.emit("trackEnd", player, trackToUse, payload);
2170
- if (this.NodeManager.LavalinkManager.options.autoSkip && player.queue.current) {
2180
+ this._LManager.emit("trackEnd", player, trackToUse, payload);
2181
+ if (this._LManager.options.autoSkip && player.queue.current) {
2171
2182
  player.play({ noReplace: true });
2172
2183
  }
2173
2184
  return;
2174
2185
  }
2175
2186
  /** @private util function for handling trackStuck event */
2176
2187
  async trackStuck(player, track, payload) {
2177
- if (this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
2178
- const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold);
2188
+ if (this._LManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
2189
+ const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this._LManager.options.playerOptions.maxErrorsPerTime?.threshold);
2179
2190
  player.set("internal_erroredTracksTimestamps", [...oldTimestamps, Date.now()]);
2180
- if (oldTimestamps.length > this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
2181
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2182
- this.NodeManager.LavalinkManager.emit("debug", "TrackStuckMaxTracksErroredPerTime" /* TrackStuckMaxTracksErroredPerTime */, {
2183
- state: "log",
2184
- message: `trackStuck Event was triggered too often within a given threshold (LavalinkManager.options.playerOptions.maxErrorsPerTime). Threshold: "${this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold}ms", maxAmount: "${this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount}"`,
2185
- functionLayer: "LavalinkNode > trackStuck()"
2186
- });
2187
- }
2191
+ if (oldTimestamps.length > this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
2192
+ this._emitDebugEvent("TrackStuckMaxTracksErroredPerTime" /* TrackStuckMaxTracksErroredPerTime */, {
2193
+ state: "log",
2194
+ 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}"`,
2195
+ functionLayer: "LavalinkNode > trackStuck()"
2196
+ });
2188
2197
  player.destroy("TrackStuckMaxTracksErroredPerTime" /* TrackStuckMaxTracksErroredPerTime */);
2189
2198
  return;
2190
2199
  }
2191
2200
  }
2192
- this.NodeManager.LavalinkManager.emit("trackStuck", player, track || this.getTrackOfPayload(payload), payload);
2201
+ this._LManager.emit("trackStuck", player, track || this.getTrackOfPayload(payload), payload);
2193
2202
  if (!player.queue.tracks.length && (player.repeatMode === "off" || player.get("internal_stopPlaying"))) {
2194
2203
  try {
2195
2204
  await player.node.updatePlayer({ guildId: player.guildId, playerOptions: { track: { encoded: null } } });
@@ -2202,54 +2211,52 @@ var LavalinkNode = class {
2202
2211
  if (!player.queue.current) {
2203
2212
  return this.queueEnd(player, track || this.getTrackOfPayload(payload), payload);
2204
2213
  }
2205
- if (this.NodeManager.LavalinkManager.options.autoSkip && player.queue.current) {
2214
+ if (this._LManager.options.autoSkip && player.queue.current) {
2206
2215
  player.play({ track: player.queue.current, noReplace: false });
2207
2216
  }
2208
2217
  return;
2209
2218
  }
2210
2219
  /** @private util function for handling trackError event */
2211
2220
  async trackError(player, track, payload) {
2212
- if (this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
2213
- const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold);
2221
+ if (this._LManager.options.playerOptions.maxErrorsPerTime?.threshold > 0 && this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount >= 0) {
2222
+ const oldTimestamps = (player.get("internal_erroredTracksTimestamps") || []).filter((v) => Date.now() - v < this._LManager.options.playerOptions.maxErrorsPerTime?.threshold);
2214
2223
  player.set("internal_erroredTracksTimestamps", [...oldTimestamps, Date.now()]);
2215
- if (oldTimestamps.length > this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
2216
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2217
- this.NodeManager.LavalinkManager.emit("debug", "TrackErrorMaxTracksErroredPerTime" /* TrackErrorMaxTracksErroredPerTime */, {
2218
- state: "log",
2219
- message: `TrackError Event was triggered too often within a given threshold (LavalinkManager.options.playerOptions.maxErrorsPerTime). Threshold: "${this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.threshold}ms", maxAmount: "${this.NodeManager.LavalinkManager.options.playerOptions.maxErrorsPerTime?.maxAmount}"`,
2220
- functionLayer: "LavalinkNode > trackError()"
2221
- });
2222
- }
2224
+ if (oldTimestamps.length > this._LManager.options.playerOptions.maxErrorsPerTime?.maxAmount) {
2225
+ this._emitDebugEvent("TrackErrorMaxTracksErroredPerTime" /* TrackErrorMaxTracksErroredPerTime */, {
2226
+ state: "log",
2227
+ 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}"`,
2228
+ functionLayer: "LavalinkNode > trackError()"
2229
+ });
2223
2230
  player.destroy("TrackErrorMaxTracksErroredPerTime" /* TrackErrorMaxTracksErroredPerTime */);
2224
2231
  return;
2225
2232
  }
2226
2233
  }
2227
- this.NodeManager.LavalinkManager.emit("trackError", player, track || this.getTrackOfPayload(payload), payload);
2234
+ this._LManager.emit("trackError", player, track || this.getTrackOfPayload(payload), payload);
2228
2235
  return;
2229
2236
  }
2230
2237
  /** @private util function for handling socketClosed event */
2231
2238
  socketClosed(player, payload) {
2232
- this.NodeManager.LavalinkManager.emit("playerSocketClosed", player, payload);
2239
+ this._LManager.emit("playerSocketClosed", player, payload);
2233
2240
  return;
2234
2241
  }
2235
2242
  /** @private util function for handling SponsorBlock Segmentloaded event */
2236
2243
  SponsorBlockSegmentLoaded(player, track, payload) {
2237
- this.NodeManager.LavalinkManager.emit("SegmentsLoaded", player, track || this.getTrackOfPayload(payload), payload);
2244
+ this._LManager.emit("SegmentsLoaded", player, track || this.getTrackOfPayload(payload), payload);
2238
2245
  return;
2239
2246
  }
2240
2247
  /** @private util function for handling SponsorBlock SegmentSkipped event */
2241
2248
  SponsorBlockSegmentSkipped(player, track, payload) {
2242
- this.NodeManager.LavalinkManager.emit("SegmentSkipped", player, track || this.getTrackOfPayload(payload), payload);
2249
+ this._LManager.emit("SegmentSkipped", player, track || this.getTrackOfPayload(payload), payload);
2243
2250
  return;
2244
2251
  }
2245
2252
  /** @private util function for handling SponsorBlock Chaptersloaded event */
2246
2253
  SponsorBlockChaptersLoaded(player, track, payload) {
2247
- this.NodeManager.LavalinkManager.emit("ChaptersLoaded", player, track || this.getTrackOfPayload(payload), payload);
2254
+ this._LManager.emit("ChaptersLoaded", player, track || this.getTrackOfPayload(payload), payload);
2248
2255
  return;
2249
2256
  }
2250
2257
  /** @private util function for handling SponsorBlock Chaptersstarted event */
2251
2258
  SponsorBlockChapterStarted(player, track, payload) {
2252
- this.NodeManager.LavalinkManager.emit("ChapterStarted", player, track || this.getTrackOfPayload(payload), payload);
2259
+ this._LManager.emit("ChapterStarted", player, track || this.getTrackOfPayload(payload), payload);
2253
2260
  return;
2254
2261
  }
2255
2262
  /**
@@ -2264,7 +2271,7 @@ var LavalinkNode = class {
2264
2271
  * ```
2265
2272
  */
2266
2273
  async getSponsorBlock(player) {
2267
- if (!this.info.plugins.find((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
2274
+ 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}`);
2268
2275
  return await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`);
2269
2276
  }
2270
2277
  /**
@@ -2279,7 +2286,7 @@ var LavalinkNode = class {
2279
2286
  * ```
2280
2287
  */
2281
2288
  async setSponsorBlock(player, segments = ["sponsor", "selfpromo"]) {
2282
- if (!this.info.plugins.find((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
2289
+ 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}`);
2283
2290
  if (!segments.length) throw new RangeError("No Segments provided. Did you ment to use 'deleteSponsorBlock'?");
2284
2291
  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(", ")}`);
2285
2292
  await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, (r) => {
@@ -2288,13 +2295,11 @@ var LavalinkNode = class {
2288
2295
  r.body = safeStringify(segments.map((v) => v.toLowerCase()));
2289
2296
  });
2290
2297
  player.set("internal_sponsorBlockCategories", segments.map((v) => v.toLowerCase()));
2291
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2292
- this.NodeManager.LavalinkManager.emit("debug", "SetSponsorBlock" /* SetSponsorBlock */, {
2293
- state: "log",
2294
- message: `SponsorBlock was set for Player: ${player.guildId} to: ${segments.map((v) => `'${v.toLowerCase()}'`).join(", ")}`,
2295
- functionLayer: "LavalinkNode > setSponsorBlock()"
2296
- });
2297
- }
2298
+ this._emitDebugEvent("SetSponsorBlock" /* SetSponsorBlock */, {
2299
+ state: "log",
2300
+ message: `SponsorBlock was set for Player: ${player.guildId} to: ${segments.map((v) => `'${v.toLowerCase()}'`).join(", ")}`,
2301
+ functionLayer: "LavalinkNode > setSponsorBlock()"
2302
+ });
2298
2303
  return;
2299
2304
  }
2300
2305
  /**
@@ -2309,18 +2314,16 @@ var LavalinkNode = class {
2309
2314
  * ```
2310
2315
  */
2311
2316
  async deleteSponsorBlock(player) {
2312
- if (!this.info.plugins.find((v) => v.name === "sponsorblock-plugin")) throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.id}`);
2317
+ 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}`);
2313
2318
  await this.request(`/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, (r) => {
2314
2319
  r.method = "DELETE";
2315
2320
  });
2316
2321
  player.set("internal_sponsorBlockCategories", []);
2317
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2318
- this.NodeManager.LavalinkManager.emit("debug", "DeleteSponsorBlock" /* DeleteSponsorBlock */, {
2319
- state: "log",
2320
- message: `SponsorBlock was deleted for Player: ${player.guildId}`,
2321
- functionLayer: "LavalinkNode > deleteSponsorBlock()"
2322
- });
2323
- }
2322
+ this._emitDebugEvent("DeleteSponsorBlock" /* DeleteSponsorBlock */, {
2323
+ state: "log",
2324
+ message: `SponsorBlock was deleted for Player: ${player.guildId}`,
2325
+ functionLayer: "LavalinkNode > deleteSponsorBlock()"
2326
+ });
2324
2327
  return;
2325
2328
  }
2326
2329
  /** private util function for handling the queue end event */
@@ -2329,46 +2332,38 @@ var LavalinkNode = class {
2329
2332
  player.queue.current = null;
2330
2333
  player.playing = false;
2331
2334
  player.set("internal_stopPlaying", void 0);
2332
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2333
- this.NodeManager.LavalinkManager.emit("debug", "QueueEnded" /* QueueEnded */, {
2335
+ this._emitDebugEvent("QueueEnded" /* QueueEnded */, {
2336
+ state: "log",
2337
+ message: `Queue Ended because no more Tracks were in the Queue, due to EventName: "${payload.type}"`,
2338
+ functionLayer: "LavalinkNode > queueEnd()"
2339
+ });
2340
+ if (typeof this._LManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction === "function" && typeof player.get("internal_autoplayStopPlaying") === "undefined") {
2341
+ this._emitDebugEvent("AutoplayExecution" /* AutoplayExecution */, {
2334
2342
  state: "log",
2335
- message: `Queue Ended because no more Tracks were in the Queue, due to EventName: "${payload.type}"`,
2336
- functionLayer: "LavalinkNode > queueEnd()"
2343
+ message: `Now Triggering Autoplay.`,
2344
+ functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2337
2345
  });
2338
- }
2339
- if (typeof this.NodeManager.LavalinkManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction === "function" && typeof player.get("internal_autoplayStopPlaying") === "undefined") {
2340
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2341
- this.NodeManager.LavalinkManager.emit("debug", "AutoplayExecution" /* AutoplayExecution */, {
2342
- state: "log",
2343
- message: `Now Triggering Autoplay.`,
2344
- functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2345
- });
2346
- }
2347
2346
  const previousAutoplayTime = player.get("internal_previousautoplay");
2348
2347
  const duration = previousAutoplayTime ? Date.now() - previousAutoplayTime : 0;
2349
- if (!duration || duration > this.NodeManager.LavalinkManager.options.playerOptions.minAutoPlayMs || !!player.get("internal_skipped")) {
2350
- await this.NodeManager.LavalinkManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction(player, track);
2348
+ if (!duration || duration > this._LManager.options.playerOptions.minAutoPlayMs || !!player.get("internal_skipped")) {
2349
+ await this._LManager.options?.playerOptions?.onEmptyQueue?.autoPlayFunction(player, track);
2351
2350
  player.set("internal_previousautoplay", Date.now());
2352
2351
  if (player.queue.tracks.length > 0) await queueTrackEnd(player);
2353
- else if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2354
- this.NodeManager.LavalinkManager.emit("debug", "AutoplayNoSongsAdded" /* AutoplayNoSongsAdded */, {
2355
- state: "warn",
2356
- message: `Autoplay was triggered but no songs were added to the queue.`,
2357
- functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2358
- });
2359
- }
2360
- if (player.queue.current) {
2361
- if (payload.type === "TrackEndEvent") this.NodeManager.LavalinkManager.emit("trackEnd", player, track, payload);
2362
- if (this.NodeManager.LavalinkManager.options.autoSkip) return player.play({ noReplace: true, paused: false });
2363
- }
2352
+ else this._emitDebugEvent("AutoplayNoSongsAdded" /* AutoplayNoSongsAdded */, {
2353
+ state: "warn",
2354
+ message: `Autoplay was triggered but no songs were added to the queue.`,
2355
+ functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2356
+ });
2357
+ }
2358
+ if (player.queue.current) {
2359
+ if (payload.type === "TrackEndEvent") this._LManager.emit("trackEnd", player, track, payload);
2360
+ if (this._LManager.options.autoSkip) return player.play({ noReplace: true, paused: false });
2364
2361
  } else {
2365
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2366
- this.NodeManager.LavalinkManager.emit("debug", "AutoplayThresholdSpamLimiter" /* AutoplayThresholdSpamLimiter */, {
2367
- state: "warn",
2368
- message: `Autoplay was triggered after the previousautoplay too early. Threshold is: ${this.NodeManager.LavalinkManager.options.playerOptions.minAutoPlayMs}ms and the Duration was ${duration}ms`,
2369
- functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2370
- });
2371
- }
2362
+ this._emitDebugEvent("AutoplayThresholdSpamLimiter" /* AutoplayThresholdSpamLimiter */, {
2363
+ state: "warn",
2364
+ message: `Autoplay was triggered after the previousautoplay too early. Threshold is: ${this._LManager.options.playerOptions.minAutoPlayMs}ms and the Duration was ${duration}ms`,
2365
+ functionLayer: "LavalinkNode > queueEnd() > autoplayFunction"
2366
+ });
2372
2367
  }
2373
2368
  }
2374
2369
  player.set("internal_skipped", false);
@@ -2381,31 +2376,29 @@ var LavalinkNode = class {
2381
2376
  if (payload?.reason !== "stopped") {
2382
2377
  await player.queue.utils.save();
2383
2378
  }
2384
- if (typeof this.NodeManager.LavalinkManager.options.playerOptions?.onEmptyQueue?.destroyAfterMs === "number" && !isNaN(this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs) && this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs >= 0) {
2385
- if (this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs === 0) {
2379
+ if (typeof this._LManager.options.playerOptions?.onEmptyQueue?.destroyAfterMs === "number" && !isNaN(this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs) && this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs >= 0) {
2380
+ if (this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs === 0) {
2386
2381
  player.destroy("QueueEmpty" /* QueueEmpty */);
2387
2382
  return;
2388
2383
  } else {
2389
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2390
- this.NodeManager.LavalinkManager.emit("debug", "TriggerQueueEmptyInterval" /* TriggerQueueEmptyInterval */, {
2391
- state: "log",
2392
- message: `Trigger Queue Empty Interval was Triggered because playerOptions.onEmptyQueue.destroyAfterMs is set to ${this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs}ms`,
2393
- functionLayer: "LavalinkNode > queueEnd() > destroyAfterMs"
2394
- });
2395
- }
2396
- this.NodeManager.LavalinkManager.emit("playerQueueEmptyStart", player, this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs);
2384
+ this._emitDebugEvent("TriggerQueueEmptyInterval" /* TriggerQueueEmptyInterval */, {
2385
+ state: "log",
2386
+ message: `Trigger Queue Empty Interval was Triggered because playerOptions.onEmptyQueue.destroyAfterMs is set to ${this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs}ms`,
2387
+ functionLayer: "LavalinkNode > queueEnd() > destroyAfterMs"
2388
+ });
2389
+ this._LManager.emit("playerQueueEmptyStart", player, this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs);
2397
2390
  if (player.get("internal_queueempty")) clearTimeout(player.get("internal_queueempty"));
2398
2391
  player.set("internal_queueempty", setTimeout(() => {
2399
2392
  player.set("internal_queueempty", void 0);
2400
2393
  if (player.queue.current) {
2401
- return this.NodeManager.LavalinkManager.emit("playerQueueEmptyCancel", player);
2394
+ return this._LManager.emit("playerQueueEmptyCancel", player);
2402
2395
  }
2403
- this.NodeManager.LavalinkManager.emit("playerQueueEmptyEnd", player);
2396
+ this._LManager.emit("playerQueueEmptyEnd", player);
2404
2397
  player.destroy("QueueEmpty" /* QueueEmpty */);
2405
- }, this.NodeManager.LavalinkManager.options.playerOptions.onEmptyQueue?.destroyAfterMs));
2398
+ }, this._LManager.options.playerOptions.onEmptyQueue?.destroyAfterMs));
2406
2399
  }
2407
2400
  }
2408
- this.NodeManager.LavalinkManager.emit("queueEnd", player, track, payload);
2401
+ this._LManager.emit("queueEnd", player, track, payload);
2409
2402
  return;
2410
2403
  }
2411
2404
  /**
@@ -2421,16 +2414,14 @@ var LavalinkNode = class {
2421
2414
  if (player.queue.current) {
2422
2415
  await player.queue.utils.save();
2423
2416
  } else {
2424
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2425
- this.NodeManager.LavalinkManager.emit("debug", "TrackStartNoTrack" /* TrackStartNoTrack */, {
2426
- state: "warn",
2427
- message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2428
- functionLayer: "LavalinkNode > trackStart()"
2429
- });
2430
- }
2417
+ this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
2418
+ state: "warn",
2419
+ message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2420
+ functionLayer: "LavalinkNode > trackStart()"
2421
+ });
2431
2422
  }
2432
2423
  }
2433
- this.NodeManager.LavalinkManager.emit("LyricsLine", player, track, payload);
2424
+ this._LManager.emit("LyricsLine", player, track, payload);
2434
2425
  return;
2435
2426
  }
2436
2427
  /**
@@ -2446,16 +2437,14 @@ var LavalinkNode = class {
2446
2437
  if (player.queue.current) {
2447
2438
  await player.queue.utils.save();
2448
2439
  } else {
2449
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2450
- this.NodeManager.LavalinkManager.emit("debug", "TrackStartNoTrack" /* TrackStartNoTrack */, {
2451
- state: "warn",
2452
- message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2453
- functionLayer: "LavalinkNode > trackStart()"
2454
- });
2455
- }
2440
+ this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
2441
+ state: "warn",
2442
+ message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2443
+ functionLayer: "LavalinkNode > trackStart()"
2444
+ });
2456
2445
  }
2457
2446
  }
2458
- this.NodeManager.LavalinkManager.emit("LyricsFound", player, track, payload);
2447
+ this._LManager.emit("LyricsFound", player, track, payload);
2459
2448
  return;
2460
2449
  }
2461
2450
  /**
@@ -2471,16 +2460,14 @@ var LavalinkNode = class {
2471
2460
  if (player.queue.current) {
2472
2461
  await player.queue.utils.save();
2473
2462
  } else {
2474
- if (this.NodeManager.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
2475
- this.NodeManager.LavalinkManager.emit("debug", "TrackStartNoTrack" /* TrackStartNoTrack */, {
2476
- state: "warn",
2477
- message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2478
- functionLayer: "LavalinkNode > trackStart()"
2479
- });
2480
- }
2463
+ this._emitDebugEvent("TrackStartNoTrack" /* TrackStartNoTrack */, {
2464
+ state: "warn",
2465
+ message: `Trackstart emitted but there is no track on player.queue.current, trying to get the track of the payload failed too.`,
2466
+ functionLayer: "LavalinkNode > trackStart()"
2467
+ });
2481
2468
  }
2482
2469
  }
2483
- this.NodeManager.LavalinkManager.emit("LyricsNotFound", player, track, payload);
2470
+ this._LManager.emit("LyricsNotFound", player, track, payload);
2484
2471
  return;
2485
2472
  }
2486
2473
  };
@@ -2842,6 +2829,21 @@ var FilterManager = class {
2842
2829
  data = structuredClone(DEFAULT_FILTER_DATAS);
2843
2830
  /** The Player assigned to this Filter Manager */
2844
2831
  player;
2832
+ get _LManager() {
2833
+ return this.player.LavalinkManager;
2834
+ }
2835
+ /**
2836
+ * Returns wether the plugin validations are enabled or not
2837
+ */
2838
+ get _checkForPlugins() {
2839
+ return !!this._LManager.options?.autoChecks?.pluginValidations;
2840
+ }
2841
+ /**
2842
+ * Returns wether the source validations are enabled or not
2843
+ */
2844
+ get _checkForSources() {
2845
+ return !!this._LManager.options?.autoChecks?.sourcesValidations;
2846
+ }
2845
2847
  /** The Constructor for the FilterManager */
2846
2848
  constructor(player) {
2847
2849
  this.player = player;
@@ -2878,13 +2880,13 @@ var FilterManager = class {
2878
2880
  if (!this.filters.karaoke) delete sendData.karaoke;
2879
2881
  if (!this.filters.rotation) delete sendData.rotation;
2880
2882
  if (this.filters.audioOutput === "stereo") delete sendData.channelMix;
2881
- if (Object.values(this.data.timescale).every((v) => v === 1)) delete sendData.timescale;
2883
+ if (Object.values(this.data.timescale ?? {}).every((v) => v === 1)) delete sendData.timescale;
2882
2884
  if (!this.player.node.sessionId) throw new Error("The Lavalink-Node is either not ready or not up to date");
2883
2885
  sendData.equalizer = [...this.equalizerBands];
2884
2886
  if (sendData.equalizer.length === 0) delete sendData.equalizer;
2885
2887
  for (const key of Object.keys(sendData)) {
2886
2888
  if (key === "pluginFilters") {
2887
- } else if (this.player.node.info && !this.player.node.info?.filters?.includes?.(key)) delete sendData[key];
2889
+ } else if (this._checkForSources && !this.player?.node?.info?.filters?.includes?.(key)) delete sendData[key];
2888
2890
  }
2889
2891
  const now = performance.now();
2890
2892
  if (this.player.options.instaUpdateFiltersFix === true) this.filterUpdatedState = true;
@@ -3024,7 +3026,7 @@ var FilterManager = class {
3024
3026
  * ```
3025
3027
  */
3026
3028
  async setAudioOutput(type) {
3027
- if (this.player.node.info && !this.player.node.info?.filters?.includes("channelMix")) throw new Error("Node#Info#filters does not include the 'channelMix' Filter (Node has it not enable)");
3029
+ 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)");
3028
3030
  if (!type || !audioOutputsData[type]) throw "Invalid audio type added, must be 'mono' / 'stereo' / 'left' / 'right'";
3029
3031
  this.data = this.data ?? {};
3030
3032
  this.data.channelMix = audioOutputsData[type];
@@ -3044,7 +3046,7 @@ var FilterManager = class {
3044
3046
  * ```
3045
3047
  */
3046
3048
  async setSpeed(speed = 1) {
3047
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
3049
+ 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)");
3048
3050
  this.data = this.data ?? {};
3049
3051
  this.filters.nightcore = false;
3050
3052
  this.filters.vaporwave = false;
@@ -3065,7 +3067,7 @@ var FilterManager = class {
3065
3067
  * ```
3066
3068
  */
3067
3069
  async setPitch(pitch = 1) {
3068
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
3070
+ 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)");
3069
3071
  this.data = this.data ?? {};
3070
3072
  this.filters.nightcore = false;
3071
3073
  this.filters.vaporwave = false;
@@ -3086,7 +3088,7 @@ var FilterManager = class {
3086
3088
  * ```
3087
3089
  */
3088
3090
  async setRate(rate = 1) {
3089
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
3091
+ 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)");
3090
3092
  this.data = this.data ?? {};
3091
3093
  this.filters.nightcore = false;
3092
3094
  this.filters.vaporwave = false;
@@ -3110,7 +3112,7 @@ var FilterManager = class {
3110
3112
  * ```
3111
3113
  */
3112
3114
  async toggleRotation(rotationHz = 0.2) {
3113
- if (this.player.node.info && !this.player.node.info?.filters?.includes("rotation")) throw new Error("Node#Info#filters does not include the 'rotation' Filter (Node has it not enable)");
3115
+ 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)");
3114
3116
  this.data = this.data ?? {};
3115
3117
  this.data.rotation = this.filters.rotation ? DEFAULT_FILTER_DATAS.rotation : { rotationHz };
3116
3118
  this.filters.rotation = !this.filters.rotation;
@@ -3133,7 +3135,7 @@ var FilterManager = class {
3133
3135
  * ```
3134
3136
  */
3135
3137
  async toggleVibrato(frequency = 10, depth = 1) {
3136
- if (this.player.node.info && !this.player.node.info?.filters?.includes("vibrato")) throw new Error("Node#Info#filters does not include the 'vibrato' Filter (Node has it not enable)");
3138
+ 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)");
3137
3139
  this.data = this.data ?? {};
3138
3140
  this.data.vibrato = this.filters.vibrato ? DEFAULT_FILTER_DATAS.vibrato : { depth, frequency };
3139
3141
  this.filters.vibrato = !this.filters.vibrato;
@@ -3156,7 +3158,7 @@ var FilterManager = class {
3156
3158
  * ```
3157
3159
  */
3158
3160
  async toggleTremolo(frequency = 4, depth = 0.8) {
3159
- if (this.player.node.info && !this.player.node.info?.filters?.includes("tremolo")) throw new Error("Node#Info#filters does not include the 'tremolo' Filter (Node has it not enable)");
3161
+ 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)");
3160
3162
  this.data = this.data ?? {};
3161
3163
  this.data.tremolo = this.filters.tremolo ? DEFAULT_FILTER_DATAS.tremolo : { depth, frequency };
3162
3164
  this.filters.tremolo = !this.filters.tremolo;
@@ -3178,7 +3180,7 @@ var FilterManager = class {
3178
3180
  * ```
3179
3181
  */
3180
3182
  async toggleLowPass(smoothing = 20) {
3181
- if (this.player.node.info && !this.player.node.info?.filters?.includes("lowPass")) throw new Error("Node#Info#filters does not include the 'lowPass' Filter (Node has it not enable)");
3183
+ 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)");
3182
3184
  this.data = this.data ?? {};
3183
3185
  this.data.lowPass = this.filters.lowPass ? DEFAULT_FILTER_DATAS.lowPass : { smoothing };
3184
3186
  this.filters.lowPass = !this.filters.lowPass;
@@ -3205,8 +3207,8 @@ var FilterManager = class {
3205
3207
  * ```
3206
3208
  */
3207
3209
  toggleLowPass: async (boostFactor = 1, cutoffFrequency = 80) => {
3208
- if (this.player.node.info && !this.player.node.info?.plugins?.find((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
3209
- if (this.player.node.info && !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)");
3210
+ 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");
3211
+ 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)");
3210
3212
  this.data = this.data ?? {};
3211
3213
  this.data.pluginFilters = this.data.pluginFilters ?? {};
3212
3214
  if (this.filters.lavalinkLavaDspxPlugin.lowPass) delete this.data.pluginFilters["low-pass"];
@@ -3231,8 +3233,8 @@ var FilterManager = class {
3231
3233
  * ```
3232
3234
  */
3233
3235
  toggleHighPass: async (boostFactor = 1, cutoffFrequency = 80) => {
3234
- if (this.player.node.info && !this.player.node.info?.plugins?.find((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
3235
- if (this.player.node.info && !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)");
3236
+ 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");
3237
+ 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)");
3236
3238
  this.data = this.data ?? {};
3237
3239
  this.data.pluginFilters = this.data.pluginFilters ?? {};
3238
3240
  if (this.filters.lavalinkLavaDspxPlugin.highPass) delete this.data.pluginFilters["high-pass"];
@@ -3257,8 +3259,8 @@ var FilterManager = class {
3257
3259
  * ```
3258
3260
  */
3259
3261
  toggleNormalization: async (maxAmplitude = 0.75, adaptive = true) => {
3260
- if (this.player.node.info && !this.player.node.info?.plugins?.find((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
3261
- if (this.player.node.info && !this.player.node.info?.filters?.includes("normalization")) throw new Error("Node#Info#filters does not include the 'normalization' Filter (Node has it not enable)");
3262
+ 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");
3263
+ 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)");
3262
3264
  this.data = this.data ?? {};
3263
3265
  this.data.pluginFilters = this.data.pluginFilters ?? {};
3264
3266
  if (this.filters.lavalinkLavaDspxPlugin.normalization) delete this.data.pluginFilters.normalization;
@@ -3283,8 +3285,8 @@ var FilterManager = class {
3283
3285
  * ```
3284
3286
  */
3285
3287
  toggleEcho: async (decay = 0.5, echoLength = 0.5) => {
3286
- if (this.player.node.info && !this.player.node.info?.plugins?.find((v) => v.name === "lavadspx-plugin")) throw new Error("Node#Info#plugins does not include the lavadspx plugin");
3287
- if (this.player.node.info && !this.player.node.info?.filters?.includes("echo")) throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable)");
3288
+ 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");
3289
+ 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)");
3288
3290
  this.data = this.data ?? {};
3289
3291
  this.data.pluginFilters = this.data.pluginFilters ?? {};
3290
3292
  if (this.filters.lavalinkLavaDspxPlugin.echo) delete this.data.pluginFilters.echo;
@@ -3314,8 +3316,8 @@ var FilterManager = class {
3314
3316
  * ```
3315
3317
  */
3316
3318
  toggleEcho: async (delay = 4, decay = 0.8) => {
3317
- if (this.player.node.info && !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");
3318
- if (this.player.node.info && !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!)");
3319
+ 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");
3320
+ 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!)");
3319
3321
  this.data = this.data ?? {};
3320
3322
  const { echo, reverb } = DEFAULT_FILTER_DATAS.pluginFilters["lavalink-filter-plugin"];
3321
3323
  this.data.pluginFilters = {
@@ -3345,8 +3347,8 @@ var FilterManager = class {
3345
3347
  * ```
3346
3348
  */
3347
3349
  toggleReverb: async (delays = [0.037, 0.042, 0.048, 0.053], gains = [0.84, 0.83, 0.82, 0.81]) => {
3348
- if (this.player.node.info && !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");
3349
- if (this.player.node.info && !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!)");
3350
+ 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");
3351
+ 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!)");
3350
3352
  this.data = this.data ?? {};
3351
3353
  const { echo, reverb } = DEFAULT_FILTER_DATAS.pluginFilters["lavalink-filter-plugin"];
3352
3354
  this.data.pluginFilters = {
@@ -3378,7 +3380,7 @@ var FilterManager = class {
3378
3380
  * ```
3379
3381
  */
3380
3382
  async toggleNightcore(speed = 1.289999523162842, pitch = 1.289999523162842, rate = 0.9365999523162842) {
3381
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
3383
+ 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)");
3382
3384
  this.data = this.data ?? {};
3383
3385
  this.data.timescale = this.filters.nightcore ? DEFAULT_FILTER_DATAS.timescale : { speed, pitch, rate };
3384
3386
  this.filters.nightcore = !this.filters.nightcore;
@@ -3404,7 +3406,7 @@ var FilterManager = class {
3404
3406
  * ```
3405
3407
  */
3406
3408
  async toggleVaporwave(speed = 0.8500000238418579, pitch = 0.800000011920929, rate = 1) {
3407
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale")) throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
3409
+ 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)");
3408
3410
  this.data = this.data ?? {};
3409
3411
  this.data.timescale = this.filters.vaporwave ? DEFAULT_FILTER_DATAS.timescale : { speed, pitch, rate };
3410
3412
  this.filters.vaporwave = !this.filters.vaporwave;
@@ -3431,7 +3433,7 @@ var FilterManager = class {
3431
3433
  * ```
3432
3434
  */
3433
3435
  async toggleKaraoke(level = 1, monoLevel = 1, filterBand = 220, filterWidth = 100) {
3434
- if (this.player.node.info && !this.player.node.info?.filters?.includes("karaoke")) throw new Error("Node#Info#filters does not include the 'karaoke' Filter (Node has it not enable)");
3436
+ 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)");
3435
3437
  this.data = this.data ?? {};
3436
3438
  this.data.karaoke = this.filters.karaoke ? DEFAULT_FILTER_DATAS.karaoke : { level, monoLevel, filterBand, filterWidth };
3437
3439
  this.filters.karaoke = !this.filters.karaoke;
@@ -3948,6 +3950,15 @@ var Player = class {
3948
3950
  };
3949
3951
  /** Custom data for the player */
3950
3952
  data = {};
3953
+ /**
3954
+ * Emits a debug event to the LavalinkManager
3955
+ * @param name name of the event
3956
+ * @param eventData event data
3957
+ */
3958
+ _emitDebugEvent(name, eventData) {
3959
+ if (!this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) return;
3960
+ this.LavalinkManager.emit("debug", name, eventData);
3961
+ }
3951
3962
  /**
3952
3963
  * Create a new Player
3953
3964
  * @param options
@@ -3963,8 +3974,8 @@ var Player = class {
3963
3974
  this.textChannelId = this.options.textChannelId || null;
3964
3975
  this.node = typeof this.options.node === "string" ? this.LavalinkManager.nodeManager.nodes.get(this.options.node) : this.options.node;
3965
3976
  if (!this.node || typeof this.node.request !== "function") {
3966
- if (typeof this.options.node === "string" && this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
3967
- this.LavalinkManager.emit("debug", "PlayerCreateNodeNotFound" /* PlayerCreateNodeNotFound */, {
3977
+ if (typeof this.options.node === "string") {
3978
+ this._emitDebugEvent("PlayerCreateNodeNotFound" /* PlayerCreateNodeNotFound */, {
3968
3979
  state: "warn",
3969
3980
  message: `Player was created with provided node Id: ${this.options.node}, but no node with that Id was found.`,
3970
3981
  functionLayer: "Player > constructor()"
@@ -4021,13 +4032,11 @@ var Player = class {
4021
4032
  */
4022
4033
  async play(options = {}) {
4023
4034
  if (this.get("internal_queueempty")) {
4024
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4025
- this.LavalinkManager.emit("debug", "PlayerPlayQueueEmptyTimeoutClear" /* PlayerPlayQueueEmptyTimeoutClear */, {
4026
- state: "log",
4027
- message: `Player was called to play something, while there was a queueEmpty Timeout set, clearing the timeout.`,
4028
- functionLayer: "Player > play()"
4029
- });
4030
- }
4035
+ this._emitDebugEvent("PlayerPlayQueueEmptyTimeoutClear" /* PlayerPlayQueueEmptyTimeoutClear */, {
4036
+ state: "log",
4037
+ message: `Player was called to play something, while there was a queueEmpty Timeout set, clearing the timeout.`,
4038
+ functionLayer: "Player > play()"
4039
+ });
4031
4040
  this.LavalinkManager.emit("playerQueueEmptyCancel", this);
4032
4041
  clearTimeout(this.get("internal_queueempty"));
4033
4042
  this.set("internal_queueempty", void 0);
@@ -4037,14 +4046,12 @@ var Player = class {
4037
4046
  try {
4038
4047
  await options.clientTrack.resolve(this);
4039
4048
  } catch (error) {
4040
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4041
- this.LavalinkManager.emit("debug", "PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
4042
- state: "error",
4043
- error,
4044
- message: `Player Play was called with clientTrack, Song is unresolved, but couldn't resolve it`,
4045
- functionLayer: "Player > play() > resolve currentTrack"
4046
- });
4047
- }
4049
+ this._emitDebugEvent("PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
4050
+ state: "error",
4051
+ error,
4052
+ message: `Player Play was called with clientTrack, Song is unresolved, but couldn't resolve it`,
4053
+ functionLayer: "Player > play() > resolve currentTrack"
4054
+ });
4048
4055
  this.LavalinkManager.emit("trackError", this, this.queue.current, error);
4049
4056
  if (options && "clientTrack" in options) delete options.clientTrack;
4050
4057
  if (options && "track" in options) delete options.track;
@@ -4081,13 +4088,11 @@ var Player = class {
4081
4088
  ...options.track.userData
4082
4089
  }
4083
4090
  }).filter((v) => typeof v[1] !== "undefined"));
4084
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4085
- this.LavalinkManager.emit("debug", "PlayerPlayWithTrackReplace" /* PlayerPlayWithTrackReplace */, {
4086
- state: "log",
4087
- message: `Player was called to play something, with a specific track provided. Replacing the current Track and resolving the track on trackStart Event.`,
4088
- functionLayer: "Player > play()"
4089
- });
4090
- }
4091
+ this._emitDebugEvent("PlayerPlayWithTrackReplace" /* PlayerPlayWithTrackReplace */, {
4092
+ state: "log",
4093
+ message: `Player was called to play something, with a specific track provided. Replacing the current Track and resolving the track on trackStart Event.`,
4094
+ functionLayer: "Player > play()"
4095
+ });
4091
4096
  return this.node.updatePlayer({
4092
4097
  guildId: this.guildId,
4093
4098
  noReplace: false,
@@ -4104,13 +4109,11 @@ var Player = class {
4104
4109
  }
4105
4110
  if (!this.queue.current && this.queue.tracks.length) await queueTrackEnd(this);
4106
4111
  if (this.queue.current && this.LavalinkManager.utils.isUnresolvedTrack(this.queue.current)) {
4107
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4108
- this.LavalinkManager.emit("debug", "PlayerPlayUnresolvedTrack" /* PlayerPlayUnresolvedTrack */, {
4109
- state: "log",
4110
- message: `Player Play was called, current Queue Song is unresolved, resolving the track.`,
4111
- functionLayer: "Player > play()"
4112
- });
4113
- }
4112
+ this._emitDebugEvent("PlayerPlayUnresolvedTrack" /* PlayerPlayUnresolvedTrack */, {
4113
+ state: "log",
4114
+ message: `Player Play was called, current Queue Song is unresolved, resolving the track.`,
4115
+ functionLayer: "Player > play()"
4116
+ });
4114
4117
  try {
4115
4118
  await this.queue.current.resolve(this);
4116
4119
  if (typeof options.track?.userData === "object" && this.queue.current) this.queue.current.userData = {
@@ -4119,14 +4122,12 @@ var Player = class {
4119
4122
  ...options.track?.userData
4120
4123
  };
4121
4124
  } catch (error) {
4122
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4123
- this.LavalinkManager.emit("debug", "PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
4124
- state: "error",
4125
- error,
4126
- message: `Player Play was called, current Queue Song is unresolved, but couldn't resolve it`,
4127
- functionLayer: "Player > play() > resolve currentTrack"
4128
- });
4129
- }
4125
+ this._emitDebugEvent("PlayerPlayUnresolvedTrackFailed" /* PlayerPlayUnresolvedTrackFailed */, {
4126
+ state: "error",
4127
+ error,
4128
+ message: `Player Play was called, current Queue Song is unresolved, but couldn't resolve it`,
4129
+ functionLayer: "Player > play() > resolve currentTrack"
4130
+ });
4130
4131
  this.LavalinkManager.emit("trackError", this, this.queue.current, error);
4131
4132
  if (options && "clientTrack" in options) delete options.clientTrack;
4132
4133
  if (options && "track" in options) delete options.track;
@@ -4187,13 +4188,11 @@ var Player = class {
4187
4188
  ), 1e3), 0));
4188
4189
  const now = performance.now();
4189
4190
  if (this.LavalinkManager.options.playerOptions.applyVolumeAsFilter) {
4190
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4191
- this.LavalinkManager.emit("debug", "PlayerVolumeAsFilter" /* PlayerVolumeAsFilter */, {
4192
- state: "log",
4193
- message: `Player Volume was set as a Filter, because LavalinkManager option "playerOptions.applyVolumeAsFilter" is true`,
4194
- functionLayer: "Player > setVolume()"
4195
- });
4196
- }
4191
+ this._emitDebugEvent("PlayerVolumeAsFilter" /* PlayerVolumeAsFilter */, {
4192
+ state: "log",
4193
+ message: `Player Volume was set as a Filter, because LavalinkManager option "playerOptions.applyVolumeAsFilter" is true`,
4194
+ functionLayer: "Player > setVolume()"
4195
+ });
4197
4196
  await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { filters: { volume: this.lavalinkVolume / 100 } } });
4198
4197
  } else {
4199
4198
  await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { volume: this.lavalinkVolume } });
@@ -4238,13 +4237,11 @@ var Player = class {
4238
4237
  async search(query, requestUser, throwOnEmpty = false) {
4239
4238
  const Query = this.LavalinkManager.utils.transformQuery(query);
4240
4239
  if (["bcsearch", "bandcamp"].includes(Query.source) && !this.node.info?.sourceManagers.includes("bandcamp")) {
4241
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4242
- this.LavalinkManager.emit("debug", "BandcampSearchLokalEngine" /* BandcampSearchLokalEngine */, {
4243
- state: "log",
4244
- message: `Player.search was called with a Bandcamp Query, but no bandcamp search was enabled on lavalink, searching with the custom Search Engine.`,
4245
- functionLayer: "Player > search()"
4246
- });
4247
- }
4240
+ this._emitDebugEvent("BandcampSearchLokalEngine" /* BandcampSearchLokalEngine */, {
4241
+ state: "log",
4242
+ message: `Player.search was called with a Bandcamp Query, but no bandcamp search was enabled on lavalink, searching with the custom Search Engine.`,
4243
+ functionLayer: "Player > search()"
4244
+ });
4248
4245
  return await bandCampSearch(this, Query.query, requestUser);
4249
4246
  }
4250
4247
  return this.node.search(Query, requestUser, throwOnEmpty);
@@ -4396,13 +4393,11 @@ var Player = class {
4396
4393
  this.set("internal_queueempty", void 0);
4397
4394
  }
4398
4395
  if (this.get("internal_destroystatus") === true) {
4399
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4400
- this.LavalinkManager.emit("debug", "PlayerDestroyingSomewhereElse" /* PlayerDestroyingSomewhereElse */, {
4401
- state: "warn",
4402
- message: `Player is already destroying somewhere else..`,
4403
- functionLayer: "Player > destroy()"
4404
- });
4405
- }
4396
+ this._emitDebugEvent("PlayerDestroyingSomewhereElse" /* PlayerDestroyingSomewhereElse */, {
4397
+ state: "warn",
4398
+ message: `Player is already destroying somewhere else..`,
4399
+ functionLayer: "Player > destroy()"
4400
+ });
4406
4401
  if (this.LavalinkManager.options.advancedOptions?.debugOptions.playerDestroy.debugLog) console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Already destroying somewhere else..`);
4407
4402
  return;
4408
4403
  }
@@ -4495,17 +4490,15 @@ var Player = class {
4495
4490
  const missingSources = [...trackSources].filter(
4496
4491
  (source) => !updateNode.info?.sourceManagers.includes(source)
4497
4492
  );
4498
- if (missingSources.length)
4493
+ if (this.LavalinkManager.options.autoChecks?.sourcesValidations && missingSources.length)
4499
4494
  throw new RangeError(`Sources missing for Node ${updateNode.id}: ${missingSources.join(", ")}`);
4500
4495
  }
4501
4496
  }
4502
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4503
- this.LavalinkManager.emit("debug", "PlayerChangeNode" /* PlayerChangeNode */, {
4504
- state: "log",
4505
- message: `Player.changeNode() was executed, trying to change from "${this.node.id}" to "${updateNode.id}"`,
4506
- functionLayer: "Player > changeNode()"
4507
- });
4508
- }
4497
+ this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
4498
+ state: "log",
4499
+ message: `Player.changeNode() was executed, trying to change from "${this.node.id}" to "${updateNode.id}"`,
4500
+ functionLayer: "Player > changeNode()"
4501
+ });
4509
4502
  const data = this.toJSON();
4510
4503
  const currentTrack = this.queue.current;
4511
4504
  if (!this.voice.endpoint || !this.voice.sessionId || !this.voice.token)
@@ -4516,30 +4509,26 @@ var Player = class {
4516
4509
  const now = performance.now();
4517
4510
  try {
4518
4511
  await this.connect();
4519
- const hasSponsorBlock = this.node.info?.plugins?.find((v) => v.name === "sponsorblock-plugin");
4512
+ const hasSponsorBlock = !this.LavalinkManager.options?.autoChecks?.pluginValidations || this.node.info?.plugins?.find((v) => v.name === "sponsorblock-plugin");
4520
4513
  if (hasSponsorBlock) {
4521
4514
  const sponsorBlockCategories = this.get("internal_sponsorBlockCategories");
4522
4515
  if (Array.isArray(sponsorBlockCategories) && sponsorBlockCategories.length) {
4523
4516
  await this.setSponsorBlock(sponsorBlockCategories).catch((error) => {
4524
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4525
- this.LavalinkManager.emit("debug", "PlayerChangeNode" /* PlayerChangeNode */, {
4526
- state: "error",
4527
- error,
4528
- message: `Player > changeNode() Unable to set SponsorBlock Segments`,
4529
- functionLayer: "Player > changeNode()"
4530
- });
4531
- }
4517
+ this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
4518
+ state: "error",
4519
+ error,
4520
+ message: `Player > changeNode() Unable to set SponsorBlock Segments`,
4521
+ functionLayer: "Player > changeNode()"
4522
+ });
4532
4523
  });
4533
4524
  } else {
4534
4525
  await this.setSponsorBlock().catch((error) => {
4535
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4536
- this.LavalinkManager.emit("debug", "PlayerChangeNode" /* PlayerChangeNode */, {
4537
- state: "error",
4538
- error,
4539
- message: `Player > changeNode() Unable to set SponsorBlock Segments`,
4540
- functionLayer: "Player > changeNode()"
4541
- });
4542
- }
4526
+ this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
4527
+ state: "error",
4528
+ error,
4529
+ message: `Player > changeNode() Unable to set SponsorBlock Segments`,
4530
+ functionLayer: "Player > changeNode()"
4531
+ });
4543
4532
  });
4544
4533
  }
4545
4534
  }
@@ -4564,25 +4553,27 @@ var Player = class {
4564
4553
  this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
4565
4554
  return this.node.id;
4566
4555
  } catch (error) {
4567
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
4568
- this.LavalinkManager.emit("debug", "PlayerChangeNode" /* PlayerChangeNode */, {
4569
- state: "error",
4570
- error,
4571
- message: `Player.changeNode() execution failed`,
4572
- functionLayer: "Player > changeNode()"
4573
- });
4574
- }
4556
+ this._emitDebugEvent("PlayerChangeNode" /* PlayerChangeNode */, {
4557
+ state: "error",
4558
+ error,
4559
+ message: `Player.changeNode() execution failed`,
4560
+ functionLayer: "Player > changeNode()"
4561
+ });
4575
4562
  throw new Error(`Failed to change the node: ${error}`);
4576
4563
  } finally {
4577
4564
  this.set("internal_nodeChanging", void 0);
4578
4565
  }
4579
4566
  }
4580
4567
  /**
4581
- * Move the player to a different node. If no node is provided, it will find the least used node that is not the same as the current node.
4568
+ * (Wrapper-FN for changeNode) Move the player to a different node. If no node is provided, it will find the least used node that is not the same as the current node.
4582
4569
  * @param node the id of the node to move to
4583
4570
  * @returns the player
4584
4571
  * @throws RangeError if there is no available nodes.
4585
4572
  * @throws Error if the node to move to is the same as the current node.
4573
+ * @example
4574
+ * ```ts
4575
+ * const newNodeMovedTo = await player.moveNode(); // no need to specify the new node, it will find a least used node automatically, but you can ofc. use a custom node id.
4576
+ * ```
4586
4577
  */
4587
4578
  async moveNode(node) {
4588
4579
  try {
@@ -4693,6 +4684,10 @@ var LavalinkManager = class extends EventEmitter2 {
4693
4684
  id: options?.client?.id,
4694
4685
  username: options?.client?.username ?? "lavalink-client"
4695
4686
  },
4687
+ autoChecks: {
4688
+ sourcesValidations: options?.autoChecks?.sourcesValidations ?? true,
4689
+ pluginValidations: options?.autoChecks?.pluginValidations ?? true
4690
+ },
4696
4691
  sendToShard: options?.sendToShard,
4697
4692
  autoMove: options?.autoMove ?? false,
4698
4693
  nodes: options?.nodes,
@@ -4756,6 +4751,8 @@ var LavalinkManager = class extends EventEmitter2 {
4756
4751
  if (options?.autoSkipOnResolveError && typeof options?.autoSkipOnResolveError !== "boolean") throw new SyntaxError("ManagerOption.autoSkipOnResolveError must be either false | true aka boolean");
4757
4752
  if (options?.emitNewSongsOnly && typeof options?.emitNewSongsOnly !== "boolean") throw new SyntaxError("ManagerOption.emitNewSongsOnly must be either false | true aka boolean");
4758
4753
  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");
4754
+ if (typeof options?.autoChecks?.sourcesValidations !== "boolean") throw new SyntaxError("ManagerOption.autoChecks.sourcesValidations must be either false | true aka boolean");
4755
+ if (typeof options?.autoChecks?.pluginValidations !== "boolean") throw new SyntaxError("ManagerOption.autoChecks.pluginValidations must be either false | true aka boolean");
4759
4756
  if (options?.queueOptions?.queueStore) {
4760
4757
  const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(options?.queueOptions?.queueStore));
4761
4758
  const requiredKeys = ["get", "set", "stringify", "parse", "delete"];
@@ -4768,6 +4765,15 @@ var LavalinkManager = class extends EventEmitter2 {
4768
4765
  }
4769
4766
  if (typeof options?.queueOptions?.maxPreviousTracks !== "number" || options?.queueOptions?.maxPreviousTracks < 0) options.queueOptions.maxPreviousTracks = 25;
4770
4767
  }
4768
+ /**
4769
+ * Emits a debug event to the LavalinkManager
4770
+ * @param name name of the event
4771
+ * @param eventData event data
4772
+ */
4773
+ _emitDebugEvent(name, eventData) {
4774
+ if (!this.options?.advancedOptions?.enableDebugEvents) return;
4775
+ this.emit("debug", name, eventData);
4776
+ }
4771
4777
  /**
4772
4778
  * Create the Lavalink Manager
4773
4779
  * @param options
@@ -4917,13 +4923,11 @@ var LavalinkManager = class extends EventEmitter2 {
4917
4923
  if (!oldPlayer) return;
4918
4924
  if (typeof oldPlayer.voiceChannelId === "string" && oldPlayer.connected && !oldPlayer.get("internal_destroywithoutdisconnect")) {
4919
4925
  if (!this.options?.advancedOptions?.debugOptions?.playerDestroy?.dontThrowError) throw new Error(`Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player ${safeStringify(oldPlayer.toJSON?.())}`);
4920
- else if (this.options?.advancedOptions?.enableDebugEvents) {
4921
- this.emit("debug", "PlayerDeleteInsteadOfDestroy" /* PlayerDeleteInsteadOfDestroy */, {
4922
- state: "warn",
4923
- message: "Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player",
4924
- functionLayer: "LavalinkManager > deletePlayer()"
4925
- });
4926
- }
4926
+ this._emitDebugEvent("PlayerDeleteInsteadOfDestroy" /* PlayerDeleteInsteadOfDestroy */, {
4927
+ state: "warn",
4928
+ message: "Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player",
4929
+ functionLayer: "LavalinkManager > deletePlayer()"
4930
+ });
4927
4931
  }
4928
4932
  return this.players.delete(guildId);
4929
4933
  }
@@ -4971,13 +4975,11 @@ var LavalinkManager = class extends EventEmitter2 {
4971
4975
  }
4972
4976
  }
4973
4977
  if (success > 0) this.initiated = true;
4974
- else if (this.options?.advancedOptions?.enableDebugEvents) {
4975
- this.emit("debug", "FailedToConnectToNodes" /* FailedToConnectToNodes */, {
4976
- state: "error",
4977
- message: "Failed to connect to at least 1 Node",
4978
- functionLayer: "LavalinkManager > init()"
4979
- });
4980
- }
4978
+ else this._emitDebugEvent("FailedToConnectToNodes" /* FailedToConnectToNodes */, {
4979
+ state: "error",
4980
+ message: "Failed to connect to at least 1 Node",
4981
+ functionLayer: "LavalinkManager > init()"
4982
+ });
4981
4983
  return this;
4982
4984
  }
4983
4985
  /**
@@ -4997,24 +4999,20 @@ var LavalinkManager = class extends EventEmitter2 {
4997
4999
  */
4998
5000
  async sendRawData(data) {
4999
5001
  if (!this.initiated) {
5000
- if (this.options?.advancedOptions?.enableDebugEvents) {
5001
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5002
- state: "log",
5003
- message: "Manager is not initated yet",
5004
- functionLayer: "LavalinkManager > sendRawData()"
5005
- });
5006
- }
5002
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5003
+ state: "log",
5004
+ message: "Manager is not initated yet",
5005
+ functionLayer: "LavalinkManager > sendRawData()"
5006
+ });
5007
5007
  if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, manager is not initated yet");
5008
5008
  return;
5009
5009
  }
5010
5010
  if (!("t" in data)) {
5011
- if (this.options?.advancedOptions?.enableDebugEvents) {
5012
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5013
- state: "error",
5014
- message: "No 't' in payload-data of the raw event:",
5015
- functionLayer: "LavalinkManager > sendRawData()"
5016
- });
5017
- }
5011
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5012
+ state: "error",
5013
+ message: "No 't' in payload-data of the raw event:",
5014
+ functionLayer: "LavalinkManager > sendRawData()"
5015
+ });
5018
5016
  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);
5019
5017
  return;
5020
5018
  }
@@ -5027,47 +5025,39 @@ var LavalinkManager = class extends EventEmitter2 {
5027
5025
  if (["VOICE_STATE_UPDATE", "VOICE_SERVER_UPDATE"].includes(data.t)) {
5028
5026
  const update = "d" in data ? data.d : data;
5029
5027
  if (!update) {
5030
- if (this.options?.advancedOptions?.enableDebugEvents) {
5031
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5032
- state: "warn",
5033
- message: `No Update data found in payload :: ${safeStringify(data, 2)}`,
5034
- functionLayer: "LavalinkManager > sendRawData()"
5035
- });
5036
- }
5028
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5029
+ state: "warn",
5030
+ message: `No Update data found in payload :: ${safeStringify(data, 2)}`,
5031
+ functionLayer: "LavalinkManager > sendRawData()"
5032
+ });
5037
5033
  if (this.options?.advancedOptions?.debugOptions?.noAudio === true) console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no update data found in payload:", data);
5038
5034
  return;
5039
5035
  }
5040
5036
  if (!("token" in update) && !("session_id" in update)) {
5041
- if (this.options?.advancedOptions?.enableDebugEvents) {
5042
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5043
- state: "error",
5044
- message: `No 'token' nor 'session_id' found in payload :: ${safeStringify(data, 2)}`,
5045
- functionLayer: "LavalinkManager > sendRawData()"
5046
- });
5047
- }
5037
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5038
+ state: "error",
5039
+ message: `No 'token' nor 'session_id' found in payload :: ${safeStringify(data, 2)}`,
5040
+ functionLayer: "LavalinkManager > sendRawData()"
5041
+ });
5048
5042
  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);
5049
5043
  return;
5050
5044
  }
5051
5045
  const player = this.getPlayer(update.guild_id);
5052
5046
  if (!player) {
5053
- if (this.options?.advancedOptions?.enableDebugEvents) {
5054
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5055
- state: "warn",
5056
- message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${safeStringify(update, 2)}`,
5057
- functionLayer: "LavalinkManager > sendRawData()"
5058
- });
5059
- }
5047
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5048
+ state: "warn",
5049
+ message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${safeStringify(update, 2)}`,
5050
+ functionLayer: "LavalinkManager > sendRawData()"
5051
+ });
5060
5052
  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);
5061
5053
  return;
5062
5054
  }
5063
5055
  if (player.get("internal_destroystatus") === true) {
5064
- if (this.options?.advancedOptions?.enableDebugEvents) {
5065
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5066
- state: "warn",
5067
- message: `Player is in a destroying state. can't signal the voice states`,
5068
- functionLayer: "LavalinkManager > sendRawData()"
5069
- });
5070
- }
5056
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5057
+ state: "warn",
5058
+ message: `Player is in a destroying state. can't signal the voice states`,
5059
+ functionLayer: "LavalinkManager > sendRawData()"
5060
+ });
5071
5061
  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");
5072
5062
  return;
5073
5063
  }
@@ -5092,13 +5082,11 @@ var LavalinkManager = class extends EventEmitter2 {
5092
5082
  }
5093
5083
  }
5094
5084
  });
5095
- if (this.options?.advancedOptions?.enableDebugEvents) {
5096
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5097
- state: "log",
5098
- message: `Sent updatePlayer for voice token session :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use }, update, playerVoice: player.voice }, 2)}`,
5099
- functionLayer: "LavalinkManager > sendRawData()"
5100
- });
5101
- }
5085
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5086
+ state: "log",
5087
+ message: `Sent updatePlayer for voice token session :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use }, update, playerVoice: player.voice }, 2)}`,
5088
+ functionLayer: "LavalinkManager > sendRawData()"
5089
+ });
5102
5090
  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 });
5103
5091
  }
5104
5092
  return;
@@ -5107,13 +5095,11 @@ var LavalinkManager = class extends EventEmitter2 {
5107
5095
  if (update.user_id && player.voiceChannelId) {
5108
5096
  this.emit(update.channel_id === player.voiceChannelId ? "playerVoiceJoin" : "playerVoiceLeave", player, update.user_id);
5109
5097
  }
5110
- if (this.options?.advancedOptions?.enableDebugEvents) {
5111
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5112
- state: "warn",
5113
- 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}"`,
5114
- functionLayer: "LavalinkManager > sendRawData()"
5115
- });
5116
- }
5098
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5099
+ state: "warn",
5100
+ 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}"`,
5101
+ functionLayer: "LavalinkManager > sendRawData()"
5102
+ });
5117
5103
  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);
5118
5104
  return;
5119
5105
  }
@@ -5121,13 +5107,11 @@ var LavalinkManager = class extends EventEmitter2 {
5121
5107
  if (player.voiceChannelId !== update.channel_id) this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
5122
5108
  player.voice.sessionId = update.session_id || player.voice.sessionId;
5123
5109
  if (!player.voice.sessionId) {
5124
- if (this.options?.advancedOptions?.enableDebugEvents) {
5125
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
5126
- state: "warn",
5127
- message: `Function to assing sessionId provided, but no found in Payload: ${safeStringify({ update, playerVoice: player.voice }, 2)}`,
5128
- functionLayer: "LavalinkManager > sendRawData()"
5129
- });
5130
- }
5110
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
5111
+ state: "warn",
5112
+ message: `Function to assing sessionId provided, but no found in Payload: ${safeStringify({ update, playerVoice: player.voice }, 2)}`,
5113
+ functionLayer: "LavalinkManager > sendRawData()"
5114
+ });
5131
5115
  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)}`);
5132
5116
  }
5133
5117
  player.voiceChannelId = update.channel_id;
@@ -5158,13 +5142,11 @@ var LavalinkManager = class extends EventEmitter2 {
5158
5142
  try {
5159
5143
  const previousPosition = player.position;
5160
5144
  const previousPaused = player.paused;
5161
- if (this.options?.advancedOptions?.enableDebugEvents) {
5162
- this.emit("debug", "PlayerAutoReconnect" /* PlayerAutoReconnect */, {
5163
- state: "log",
5164
- message: `Auto reconnecting player because LavalinkManager.options.playerOptions.onDisconnect.autoReconnect is true`,
5165
- functionLayer: "LavalinkManager > sendRawData()"
5166
- });
5167
- }
5145
+ this._emitDebugEvent("PlayerAutoReconnect" /* PlayerAutoReconnect */, {
5146
+ state: "log",
5147
+ message: `Auto reconnecting player because LavalinkManager.options.playerOptions.onDisconnect.autoReconnect is true`,
5148
+ functionLayer: "LavalinkManager > sendRawData()"
5149
+ });
5168
5150
  if (!autoReconnectOnlyWithTracks || autoReconnectOnlyWithTracks && (player.queue.current || player.queue.tracks.length)) {
5169
5151
  await player.connect();
5170
5152
  }
@@ -5174,13 +5156,11 @@ var LavalinkManager = class extends EventEmitter2 {
5174
5156
  if (player.queue.tracks.length) {
5175
5157
  return void await player.play({ paused: previousPaused });
5176
5158
  }
5177
- if (this.options?.advancedOptions?.enableDebugEvents) {
5178
- this.emit("debug", "PlayerAutoReconnect" /* PlayerAutoReconnect */, {
5179
- state: "log",
5180
- message: `Auto reconnected, but nothing to play`,
5181
- functionLayer: "LavalinkManager > sendRawData()"
5182
- });
5183
- }
5159
+ this._emitDebugEvent("PlayerAutoReconnect" /* PlayerAutoReconnect */, {
5160
+ state: "log",
5161
+ message: `Auto reconnected, but nothing to play`,
5162
+ functionLayer: "LavalinkManager > sendRawData()"
5163
+ });
5184
5164
  return;
5185
5165
  } catch (e) {
5186
5166
  console.error(e);