lavalink-client 2.9.4 → 2.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6046,7 +6046,7 @@ var Player = class {
6046
6046
  };
6047
6047
 
6048
6048
  // src/structures/LavalinkManager.ts
6049
- var LavalinkManager = class extends EventEmitter2 {
6049
+ var LavalinkManager = class _LavalinkManager extends EventEmitter2 {
6050
6050
  /**
6051
6051
  * Emit an event
6052
6052
  * @param event The event to emit
@@ -6215,6 +6215,17 @@ var LavalinkManager = class extends EventEmitter2 {
6215
6215
  if (!this.options?.advancedOptions?.enableDebugEvents) return;
6216
6216
  this.emit("debug", name, eventData);
6217
6217
  }
6218
+ static _noAudioDebugPrefix = "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, ";
6219
+ /**
6220
+ * Emits NoAudioDebug and optionally logs to console when debugOptions.noAudio is enabled.
6221
+ */
6222
+ _debugNoAudio(state, functionLayer, messages, ...consoleArgs) {
6223
+ this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, { state, functionLayer, message: messages.message });
6224
+ if (this.options?.advancedOptions?.debugOptions?.noAudio === true) {
6225
+ const consoleMsg = messages.consoleMessage ?? messages.message;
6226
+ console.debug(_LavalinkManager._noAudioDebugPrefix + consoleMsg, ...consoleArgs);
6227
+ }
6228
+ }
6218
6229
  /**
6219
6230
  * Create the Lavalink Manager
6220
6231
  * @param options
@@ -6446,28 +6457,22 @@ var LavalinkManager = class extends EventEmitter2 {
6446
6457
  */
6447
6458
  async sendRawData(data) {
6448
6459
  if (!this.initiated) {
6449
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6450
- state: "log",
6460
+ this._debugNoAudio("log", "LavalinkManager > sendRawData()", {
6451
6461
  message: "Manager is not initated yet",
6452
- functionLayer: "LavalinkManager > sendRawData()"
6462
+ consoleMessage: "manager is not initated yet"
6453
6463
  });
6454
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6455
- console.debug(
6456
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, manager is not initated yet"
6457
- );
6458
6464
  return;
6459
6465
  }
6460
6466
  if (!("t" in data)) {
6461
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6462
- state: "error",
6463
- message: "No 't' in payload-data of the raw event:",
6464
- functionLayer: "LavalinkManager > sendRawData()"
6465
- });
6466
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6467
- console.debug(
6468
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 't' in payload-data of the raw event:",
6469
- data
6470
- );
6467
+ this._debugNoAudio(
6468
+ "error",
6469
+ "LavalinkManager > sendRawData()",
6470
+ {
6471
+ message: "No 't' in payload-data of the raw event:",
6472
+ consoleMessage: "no 't' in payload-data of the raw event:"
6473
+ },
6474
+ data
6475
+ );
6471
6476
  return;
6472
6477
  }
6473
6478
  if ("CHANNEL_DELETE" === data.t) {
@@ -6480,132 +6485,94 @@ var LavalinkManager = class extends EventEmitter2 {
6480
6485
  if (["VOICE_STATE_UPDATE", "VOICE_SERVER_UPDATE"].includes(data.t)) {
6481
6486
  const update = "d" in data ? data.d : data;
6482
6487
  if (!update) {
6483
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6484
- state: "warn",
6485
- message: `No Update data found in payload :: ${safeStringify(data, 2)}`,
6486
- functionLayer: "LavalinkManager > sendRawData()"
6487
- });
6488
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6489
- console.debug(
6490
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no update data found in payload:",
6491
- data
6492
- );
6488
+ this._debugNoAudio(
6489
+ "warn",
6490
+ "LavalinkManager > sendRawData()",
6491
+ {
6492
+ message: `No Update data found in payload :: ${safeStringify(data, 2)}`,
6493
+ consoleMessage: "no update data found in payload:"
6494
+ },
6495
+ data
6496
+ );
6493
6497
  return;
6494
6498
  }
6495
6499
  if (!("token" in update) && !("session_id" in update)) {
6496
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6497
- state: "error",
6498
- message: `No 'token' nor 'session_id' found in payload :: ${safeStringify(data, 2)}`,
6499
- functionLayer: "LavalinkManager > sendRawData()"
6500
- });
6501
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6502
- console.debug(
6503
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 'token' nor 'session_id' found in payload:",
6504
- data
6505
- );
6500
+ this._debugNoAudio(
6501
+ "error",
6502
+ "LavalinkManager > sendRawData()",
6503
+ {
6504
+ message: `No 'token' nor 'session_id' found in payload :: ${safeStringify(data, 2)}`,
6505
+ consoleMessage: "no 'token' nor 'session_id' found in payload:"
6506
+ },
6507
+ data
6508
+ );
6506
6509
  return;
6507
6510
  }
6508
6511
  const player = this.getPlayer(update.guild_id);
6509
6512
  if (!player) {
6510
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6511
- state: "warn",
6512
- message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${safeStringify(update, 2)}`,
6513
- functionLayer: "LavalinkManager > sendRawData()"
6514
- });
6515
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6516
- console.debug(
6517
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, No Lavalink Player found via key: 'guild_id' of update-data:",
6518
- update
6519
- );
6513
+ this._debugNoAudio(
6514
+ "warn",
6515
+ "LavalinkManager > sendRawData()",
6516
+ {
6517
+ message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${safeStringify(update, 2)}`,
6518
+ consoleMessage: "No Lavalink Player found via key: 'guild_id' of update-data:"
6519
+ },
6520
+ update
6521
+ );
6520
6522
  return;
6521
6523
  }
6522
6524
  if (player.get("internal_destroystatus") === true) {
6523
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6524
- state: "warn",
6525
- message: `Player is in a destroying state. can't signal the voice states`,
6526
- functionLayer: "LavalinkManager > sendRawData()"
6525
+ this._debugNoAudio("warn", "LavalinkManager > sendRawData()", {
6526
+ message: "Player is in a destroying state. can't signal the voice states"
6527
6527
  });
6528
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6529
- console.debug(
6530
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Player is in a destroying state. can't signal the voice states"
6531
- );
6532
6528
  return;
6533
6529
  }
6534
6530
  if ("token" in update) {
6535
6531
  if (!player.node?.sessionId) throw new Error("Lavalink Node is either not ready or not up to date");
6536
6532
  const sessionId2Use = player.voice?.sessionId || ("sessionId" in update ? update.sessionId : void 0);
6537
6533
  const channelId2Use = player.voice?.channelId || ("channel_id" in update ? update.channel_id : void 0);
6534
+ const voiceData = {
6535
+ token: update.token,
6536
+ endpoint: update.endpoint,
6537
+ sessionId: sessionId2Use,
6538
+ channelId: channelId2Use
6539
+ };
6538
6540
  if (!sessionId2Use) {
6539
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
6540
- state: "error",
6541
- message: `Can't send updatePlayer for voice token session - Missing sessionId :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, channelId: channelId2Use }, update, playerVoice: player.voice }, 2)}`,
6542
- functionLayer: "LavalinkManager > sendRawData()"
6543
- });
6544
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6545
- console.debug(
6546
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Can't send updatePlayer for voice token session - Missing sessionId",
6547
- {
6548
- voice: {
6549
- token: update.token,
6550
- endpoint: update.endpoint,
6551
- sessionId: sessionId2Use,
6552
- channelId: channelId2Use
6553
- },
6554
- update,
6555
- playerVoice: player.voice
6556
- }
6557
- );
6541
+ this._debugNoAudio(
6542
+ "error",
6543
+ "LavalinkManager > sendRawData()",
6544
+ {
6545
+ message: `Can't send updatePlayer for voice token session - Missing sessionId :: ${safeStringify({ voice: voiceData, update, playerVoice: player.voice }, 2)}`,
6546
+ consoleMessage: "Can't send updatePlayer for voice token session - Missing sessionId"
6547
+ },
6548
+ { voice: voiceData, update, playerVoice: player.voice }
6549
+ );
6558
6550
  } else if (!channelId2Use) {
6559
- this.emit("debug", "NoAudioDebug" /* NoAudioDebug */, {
6560
- state: "error",
6561
- message: `Can't send updatePlayer for voice token session - Missing channelId :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, channelId: channelId2Use }, update, playerVoice: player.voice }, 2)}`,
6562
- functionLayer: "LavalinkManager > sendRawData()"
6563
- });
6564
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6565
- console.debug(
6566
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Can't send updatePlayer for voice token session - Missing channelId",
6567
- {
6568
- voice: {
6569
- token: update.token,
6570
- endpoint: update.endpoint,
6571
- sessionId: sessionId2Use,
6572
- channelId: channelId2Use
6573
- },
6574
- update,
6575
- playerVoice: player.voice
6576
- }
6577
- );
6551
+ this._debugNoAudio(
6552
+ "error",
6553
+ "LavalinkManager > sendRawData()",
6554
+ {
6555
+ message: `Can't send updatePlayer for voice token session - Missing channelId :: ${safeStringify({ voice: voiceData, update, playerVoice: player.voice }, 2)}`,
6556
+ consoleMessage: "Can't send updatePlayer for voice token session - Missing channelId"
6557
+ },
6558
+ { voice: voiceData, update, playerVoice: player.voice }
6559
+ );
6578
6560
  } else {
6579
6561
  await player.node.updatePlayer({
6580
6562
  guildId: player.guildId,
6581
6563
  playerOptions: {
6582
- voice: {
6583
- token: update.token,
6584
- endpoint: update.endpoint,
6585
- sessionId: sessionId2Use,
6586
- channelId: channelId2Use
6587
- }
6564
+ voice: voiceData
6588
6565
  }
6589
6566
  });
6590
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6591
- state: "log",
6592
- message: `Sent updatePlayer for voice token session :: ${safeStringify({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, channelId: channelId2Use }, update, playerVoice: player.voice }, 2)}`,
6593
- functionLayer: "LavalinkManager > sendRawData()"
6594
- });
6595
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6596
- console.debug(
6597
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session",
6598
- {
6599
- voice: {
6600
- token: update.token,
6601
- endpoint: update.endpoint,
6602
- sessionId: sessionId2Use,
6603
- channelId: channelId2Use
6604
- },
6605
- playerVoice: player.voice,
6606
- update
6607
- }
6608
- );
6567
+ this._debugNoAudio(
6568
+ "log",
6569
+ "LavalinkManager > sendRawData()",
6570
+ {
6571
+ message: `Sent updatePlayer for voice token session :: ${safeStringify({ voice: voiceData, update, playerVoice: player.voice }, 2)}`,
6572
+ consoleMessage: "Sent updatePlayer for voice token session"
6573
+ },
6574
+ { voice: voiceData, playerVoice: player.voice, update }
6575
+ );
6609
6576
  }
6610
6577
  return;
6611
6578
  }
@@ -6617,36 +6584,30 @@ var LavalinkManager = class extends EventEmitter2 {
6617
6584
  update.user_id
6618
6585
  );
6619
6586
  }
6620
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6621
- state: "warn",
6622
- 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}"`,
6623
- functionLayer: "LavalinkManager > sendRawData()"
6624
- });
6625
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6626
- console.debug(
6627
- "Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, voice update user is not equal to provided client id of the manageroptions#client#id",
6628
- "user:",
6629
- update.user_id,
6630
- "manager client id:",
6631
- this.options?.client.id
6632
- );
6587
+ this._debugNoAudio(
6588
+ "warn",
6589
+ "LavalinkManager > sendRawData()",
6590
+ {
6591
+ 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}"`,
6592
+ consoleMessage: "voice update user is not equal to provided client id of the manageroptions#client#id"
6593
+ },
6594
+ "user:",
6595
+ update.user_id,
6596
+ "manager client id:",
6597
+ this.options?.client.id
6598
+ );
6633
6599
  return;
6634
6600
  }
6635
6601
  if (update.channel_id) {
6636
6602
  if (player.voiceChannelId !== update.channel_id)
6637
6603
  this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
6638
6604
  player.voice.sessionId = update.session_id || player.voice.sessionId;
6639
- player.voice.channelId = update.channel_id;
6605
+ player.voice.channelId = update.channel_id || player.voice.channelId;
6640
6606
  if (!player.voice.sessionId) {
6641
- this._emitDebugEvent("NoAudioDebug" /* NoAudioDebug */, {
6642
- state: "warn",
6607
+ this._debugNoAudio("warn", "LavalinkManager > sendRawData()", {
6643
6608
  message: `Function to assing sessionId provided, but no found in Payload: ${safeStringify({ update, playerVoice: player.voice }, 2)}`,
6644
- functionLayer: "LavalinkManager > sendRawData()"
6609
+ consoleMessage: `Function to assing sessionId provided, but no found in Payload: ${safeStringify(update, 2)}`
6645
6610
  });
6646
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
6647
- console.debug(
6648
- `Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Function to assing sessionId provided, but no found in Payload: ${safeStringify(update, 2)}`
6649
- );
6650
6611
  }
6651
6612
  player.voiceChannelId = update.channel_id;
6652
6613
  player.options.voiceChannelId = update.channel_id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "2.9.4",
3
+ "version": "2.9.6",
4
4
  "description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients. - Supports NodeLink@v3 too.",
5
5
  "keywords": [
6
6
  "advanced",
@@ -33,15 +33,16 @@
33
33
  "dist"
34
34
  ],
35
35
  "type": "module",
36
- "main": "./dist/index.js",
36
+ "main": "./dist/index.cjs",
37
37
  "module": "./dist/index.mjs",
38
38
  "types": "./dist/index.d.ts",
39
39
  "exports": {
40
40
  ".": {
41
41
  "types": "./dist/index.d.ts",
42
- "require": "./dist/index.js",
42
+ "bun": "./dist/index.mjs",
43
+ "require": "./dist/index.cjs",
43
44
  "import": "./dist/index.mjs",
44
- "default": "./dist/index.js"
45
+ "default": "./dist/index.mjs"
45
46
  }
46
47
  },
47
48
  "publishConfig": {