magmastream 2.9.2-dev.9 → 2.9.3-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -83,6 +83,7 @@ declare enum SearchPlatform {
83
83
  SoundCloud = "scsearch",
84
84
  Spotify = "spsearch",
85
85
  Tidal = "tdsearch",
86
+ TTS = "speak",
86
87
  VKMusic = "vksearch",
87
88
  YouTube = "ytsearch",
88
89
  YouTubeMusic = "ytmsearch"
@@ -1181,7 +1182,7 @@ interface Track {
1181
1182
  /** The thumbnail of the track or null if it's a unsupported source. */
1182
1183
  readonly thumbnail: string | null;
1183
1184
  /** The user that requested the track. */
1184
- requester?: AnyUser;
1185
+ requester: AnyUser;
1185
1186
  /** Displays the track thumbnail with optional size or null if it's a unsupported source. */
1186
1187
  displayThumbnail(size?: Sizes): string | null;
1187
1188
  /** Additional track info provided by plugins. */
@@ -1840,6 +1841,8 @@ interface PlayerOptions {
1840
1841
  selfDeafen?: boolean;
1841
1842
  /** Whether to apply the volume as a filter. */
1842
1843
  applyVolumeAsFilter?: boolean;
1844
+ /** Whether to pause the player when the voice connection is disconnected. */
1845
+ pauseOnDisconnect?: boolean;
1843
1846
  }
1844
1847
  /**
1845
1848
  * PlayOptions interface
@@ -2275,7 +2278,7 @@ declare class Player {
2275
2278
  * @throws {Error} If there are no previous tracks in the queue.
2276
2279
  * @emits {PlayerStateUpdate} - With {@link PlayerStateEventTypes.TrackChange} as the change type.
2277
2280
  */
2278
- previous(): Promise<this>;
2281
+ previous(addBackToQueue?: boolean): Promise<this>;
2279
2282
  /**
2280
2283
  * Seeks to a given position in the currently playing track.
2281
2284
  * @param position - The position in milliseconds to seek to.
@@ -100,7 +100,7 @@ class JsonQueue {
100
100
  if (!tracks.length)
101
101
  return;
102
102
  const current = await this.getPrevious();
103
- const newTracks = tracks.filter((t) => !current.some((p) => p.identifier === t.identifier));
103
+ const newTracks = tracks.filter((t) => !current.some((p) => p.uri === t.uri));
104
104
  if (!newTracks.length)
105
105
  return;
106
106
  const updated = [...current, ...newTracks];
@@ -569,6 +569,8 @@ class JsonQueue {
569
569
  async readJSON(filePath) {
570
570
  try {
571
571
  const raw = await fs_1.promises.readFile(filePath, "utf-8");
572
+ if (!raw || !raw.trim())
573
+ return null;
572
574
  return JSON.parse(raw);
573
575
  }
574
576
  catch (err) {
@@ -71,6 +71,7 @@ var SearchPlatform;
71
71
  SearchPlatform["SoundCloud"] = "scsearch";
72
72
  SearchPlatform["Spotify"] = "spsearch";
73
73
  SearchPlatform["Tidal"] = "tdsearch";
74
+ SearchPlatform["TTS"] = "speak";
74
75
  SearchPlatform["VKMusic"] = "vksearch";
75
76
  SearchPlatform["YouTube"] = "ytsearch";
76
77
  SearchPlatform["YouTubeMusic"] = "ytmsearch";
@@ -1106,7 +1106,9 @@ class Manager extends events_1.EventEmitter {
1106
1106
  this.emit(Enums_1.ManagerEventTypes.PlayerDisconnect, player, player.voiceChannelId);
1107
1107
  player.voiceChannelId = null;
1108
1108
  player.voiceState = Object.assign({});
1109
- await player.pause(true);
1109
+ if (player.options.pauseOnDisconnect) {
1110
+ await player.pause(true);
1111
+ }
1110
1112
  return;
1111
1113
  }
1112
1114
  /**
@@ -91,6 +91,7 @@ class Player {
91
91
  selfMute: options.selfMute ?? false,
92
92
  selfDeafen: options.selfDeafen ?? false,
93
93
  volume: options.volume ?? 100,
94
+ pauseOnDisconnect: options.pauseOnDisconnect ?? true,
94
95
  };
95
96
  // Set the guild ID and voice state.
96
97
  this.guildId = options.guildId;
@@ -364,10 +365,12 @@ class Player {
364
365
  await this.queue.setCurrent(optionsOrTrack);
365
366
  }
366
367
  if (!(await this.queue.getCurrent())) {
367
- throw new MagmastreamError_1.MagmaStreamError({
368
+ const error = new MagmastreamError_1.MagmaStreamError({
368
369
  code: Enums_1.MagmaStreamErrorCode.PLAYER_QUEUE_EMPTY,
369
370
  message: "The queue is empty.",
370
371
  });
372
+ console.error(error);
373
+ return this;
371
374
  }
372
375
  const finalOptions = playOptions
373
376
  ? playOptions
@@ -399,17 +402,21 @@ class Player {
399
402
  */
400
403
  setAutoplay(autoplayState, AutoplayUser, tries) {
401
404
  if (typeof autoplayState !== "boolean") {
402
- throw new MagmastreamError_1.MagmaStreamError({
405
+ const error = new MagmastreamError_1.MagmaStreamError({
403
406
  code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_AUTOPLAY,
404
407
  message: "autoplayState must be a boolean.",
405
408
  });
409
+ console.error(error);
410
+ return this;
406
411
  }
407
412
  if (autoplayState) {
408
413
  if (!AutoplayUser) {
409
- throw new MagmastreamError_1.MagmaStreamError({
414
+ const error = new MagmastreamError_1.MagmaStreamError({
410
415
  code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_AUTOPLAY,
411
416
  message: "AutoplayUser must be provided when enabling autoplay.",
412
417
  });
418
+ console.error(error);
419
+ return this;
413
420
  }
414
421
  this.autoplayTries = tries && typeof tries === "number" && tries > 0 ? tries : 3; // Default to 3 if invalid
415
422
  this.isAutoplay = true;
@@ -775,21 +782,33 @@ class Player {
775
782
  * @throws {Error} If there are no previous tracks in the queue.
776
783
  * @emits {PlayerStateUpdate} - With {@link PlayerStateEventTypes.TrackChange} as the change type.
777
784
  */
778
- async previous() {
785
+ async previous(addBackToQueue = true) {
779
786
  // Pop the most recent previous track (from tail)
780
787
  const lastTrack = await this.queue.popPrevious();
781
788
  if (!lastTrack) {
782
789
  await this.queue.clearPrevious();
783
- throw new MagmastreamError_1.MagmaStreamError({
790
+ const error = new MagmastreamError_1.MagmaStreamError({
784
791
  code: Enums_1.MagmaStreamErrorCode.PLAYER_PREVIOUS_EMPTY,
785
792
  message: "Previous queue is empty.",
786
793
  });
794
+ console.error(error);
795
+ return this;
787
796
  }
788
797
  // Capture the current state of the player before making changes.
789
798
  const oldPlayer = { ...this };
790
799
  // Prevent re-adding the current track
791
800
  this.set("skipFlag", true);
792
- await this.play(lastTrack);
801
+ // Add the current track to the queue if addBackToQueue is true
802
+ if (addBackToQueue) {
803
+ const currentPlayingTrack = await this.queue.getCurrent();
804
+ if (currentPlayingTrack) {
805
+ await this.queue.add(currentPlayingTrack, 0);
806
+ }
807
+ await this.play(lastTrack);
808
+ }
809
+ else {
810
+ await this.play(lastTrack);
811
+ }
793
812
  this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
794
813
  changeType: Enums_1.PlayerStateEventTypes.TrackChange,
795
814
  details: {
@@ -15,7 +15,7 @@ function playerCheck(options) {
15
15
  message: "PlayerOptions must not be empty.",
16
16
  });
17
17
  }
18
- const { guildId, nodeIdentifier, selfDeafen, selfMute, textChannelId, voiceChannelId, volume, applyVolumeAsFilter } = options;
18
+ const { guildId, nodeIdentifier, selfDeafen, selfMute, textChannelId, voiceChannelId, volume, applyVolumeAsFilter, pauseOnDisconnect } = options;
19
19
  if (!/^\d+$/.test(guildId)) {
20
20
  throw new MagmastreamError_1.MagmaStreamError({
21
21
  code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
@@ -72,4 +72,11 @@ function playerCheck(options) {
72
72
  context: { applyVolumeAsFilter },
73
73
  });
74
74
  }
75
+ if (typeof pauseOnDisconnect !== "undefined" && typeof pauseOnDisconnect !== "boolean") {
76
+ throw new MagmastreamError_1.MagmaStreamError({
77
+ code: Enums_1.MagmaStreamErrorCode.PLAYER_INVALID_CONFIG,
78
+ message: 'Player option "pauseOnDisconnect" must be a boolean.',
79
+ context: { pauseOnDisconnect },
80
+ });
81
+ }
75
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.9.2-dev.9",
3
+ "version": "2.9.3-dev.0",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",