distube 5.0.3 → 5.0.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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { Snowflake, Message, GuildTextBasedChannel, VoiceBasedChannel, VoiceState, Guild, GuildMember, Interaction, Client, Collection, ClientOptions } from 'discord.js';
2
+ import { GuildMember, Snowflake, Message, GuildTextBasedChannel, VoiceBasedChannel, VoiceState, Guild, Interaction, Client, Collection, ClientOptions } from 'discord.js';
3
3
  import { TypedEmitter } from 'tiny-typed-emitter';
4
4
  import { AudioPlayer, VoiceConnection, AudioResource } from '@discordjs/voice';
5
5
  import { Transform, TransformCallback } from 'stream';
@@ -637,6 +637,7 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
637
637
  emittedError: boolean;
638
638
  isDisconnected: boolean;
639
639
  stream?: DisTubeStream;
640
+ pausingStream?: DisTubeStream;
640
641
  constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel);
641
642
  /**
642
643
  * The voice channel id the bot is in
@@ -664,7 +665,7 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
664
665
  * Play a {@link DisTubeStream}
665
666
  * @param dtStream - DisTubeStream
666
667
  */
667
- play(dtStream: DisTubeStream): void;
668
+ play(dtStream: DisTubeStream): Promise<void>;
668
669
  set volume(volume: number);
669
670
  /**
670
671
  * Get or set the volume percentage
@@ -1026,12 +1027,12 @@ declare class Queue extends DisTubeBase {
1026
1027
  * Pause the guild stream
1027
1028
  * @returns The guild queue
1028
1029
  */
1029
- pause(): Queue;
1030
+ pause(): Promise<Queue>;
1030
1031
  /**
1031
1032
  * Resume the guild stream
1032
1033
  * @returns The guild queue
1033
1034
  */
1034
- resume(): Queue;
1035
+ resume(): Promise<Queue>;
1035
1036
  /**
1036
1037
  * Set the guild stream's volume
1037
1038
  * @param percent - The percentage of volume you want to set
@@ -1234,7 +1235,7 @@ declare function objectKeys<T>(obj: T): KeyOf<T>;
1234
1235
  declare function isNsfwChannel(channel?: GuildTextBasedChannel): boolean;
1235
1236
  type Falsy = undefined | null | false | 0 | "";
1236
1237
  declare const isTruthy: <T>(x: T | Falsy) => x is T;
1237
- declare const checkEncryptionLibraries: () => boolean;
1238
+ declare const checkEncryptionLibraries: () => Promise<boolean>;
1238
1239
 
1239
1240
  /**
1240
1241
  * DisTube class
@@ -1390,13 +1391,13 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
1390
1391
  * @param guild - The type can be resolved to give a {@link Queue}
1391
1392
  * @returns The guild queue
1392
1393
  */
1393
- pause(guild: GuildIdResolvable): Queue;
1394
+ pause(guild: GuildIdResolvable): Promise<Queue>;
1394
1395
  /**
1395
1396
  * Resume the guild stream
1396
1397
  * @param guild - The type can be resolved to give a {@link Queue}
1397
1398
  * @returns The guild queue
1398
1399
  */
1399
- resume(guild: GuildIdResolvable): Queue;
1400
+ resume(guild: GuildIdResolvable): Promise<Queue>;
1400
1401
  /**
1401
1402
  * Stop the guild stream
1402
1403
  * @param guild - The type can be resolved to give a {@link Queue}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { Snowflake, Message, GuildTextBasedChannel, VoiceBasedChannel, VoiceState, Guild, GuildMember, Interaction, Client, Collection, ClientOptions } from 'discord.js';
2
+ import { GuildMember, Snowflake, Message, GuildTextBasedChannel, VoiceBasedChannel, VoiceState, Guild, Interaction, Client, Collection, ClientOptions } from 'discord.js';
3
3
  import { TypedEmitter } from 'tiny-typed-emitter';
4
4
  import { AudioPlayer, VoiceConnection, AudioResource } from '@discordjs/voice';
5
5
  import { Transform, TransformCallback } from 'stream';
@@ -637,6 +637,7 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
637
637
  emittedError: boolean;
638
638
  isDisconnected: boolean;
639
639
  stream?: DisTubeStream;
640
+ pausingStream?: DisTubeStream;
640
641
  constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel);
641
642
  /**
642
643
  * The voice channel id the bot is in
@@ -664,7 +665,7 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
664
665
  * Play a {@link DisTubeStream}
665
666
  * @param dtStream - DisTubeStream
666
667
  */
667
- play(dtStream: DisTubeStream): void;
668
+ play(dtStream: DisTubeStream): Promise<void>;
668
669
  set volume(volume: number);
669
670
  /**
670
671
  * Get or set the volume percentage
@@ -1026,12 +1027,12 @@ declare class Queue extends DisTubeBase {
1026
1027
  * Pause the guild stream
1027
1028
  * @returns The guild queue
1028
1029
  */
1029
- pause(): Queue;
1030
+ pause(): Promise<Queue>;
1030
1031
  /**
1031
1032
  * Resume the guild stream
1032
1033
  * @returns The guild queue
1033
1034
  */
1034
- resume(): Queue;
1035
+ resume(): Promise<Queue>;
1035
1036
  /**
1036
1037
  * Set the guild stream's volume
1037
1038
  * @param percent - The percentage of volume you want to set
@@ -1234,7 +1235,7 @@ declare function objectKeys<T>(obj: T): KeyOf<T>;
1234
1235
  declare function isNsfwChannel(channel?: GuildTextBasedChannel): boolean;
1235
1236
  type Falsy = undefined | null | false | 0 | "";
1236
1237
  declare const isTruthy: <T>(x: T | Falsy) => x is T;
1237
- declare const checkEncryptionLibraries: () => boolean;
1238
+ declare const checkEncryptionLibraries: () => Promise<boolean>;
1238
1239
 
1239
1240
  /**
1240
1241
  * DisTube class
@@ -1390,13 +1391,13 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
1390
1391
  * @param guild - The type can be resolved to give a {@link Queue}
1391
1392
  * @returns The guild queue
1392
1393
  */
1393
- pause(guild: GuildIdResolvable): Queue;
1394
+ pause(guild: GuildIdResolvable): Promise<Queue>;
1394
1395
  /**
1395
1396
  * Resume the guild stream
1396
1397
  * @param guild - The type can be resolved to give a {@link Queue}
1397
1398
  * @returns The guild queue
1398
1399
  */
1399
- resume(guild: GuildIdResolvable): Queue;
1400
+ resume(guild: GuildIdResolvable): Promise<Queue>;
1400
1401
  /**
1401
1402
  * Stop the guild stream
1402
1403
  * @param guild - The type can be resolved to give a {@link Queue}
package/dist/index.js CHANGED
@@ -19,8 +19,8 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
 
21
21
  // src/index.ts
22
- var src_exports = {};
23
- __export(src_exports, {
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
24
  BaseManager: () => BaseManager,
25
25
  DisTube: () => DisTube,
26
26
  DisTubeBase: () => DisTubeBase,
@@ -68,7 +68,7 @@ __export(src_exports, {
68
68
  resolveGuildId: () => resolveGuildId,
69
69
  version: () => version
70
70
  });
71
- module.exports = __toCommonJS(src_exports);
71
+ module.exports = __toCommonJS(index_exports);
72
72
 
73
73
  // src/type.ts
74
74
  var Events = /* @__PURE__ */ ((Events2) => {
@@ -563,6 +563,7 @@ var DisTubeVoice = class extends import_tiny_typed_emitter.TypedEmitter {
563
563
  emittedError;
564
564
  isDisconnected = false;
565
565
  stream;
566
+ pausingStream;
566
567
  #channel;
567
568
  #volume = 100;
568
569
  constructor(voiceManager, channel) {
@@ -685,8 +686,8 @@ var DisTubeVoice = class extends import_tiny_typed_emitter.TypedEmitter {
685
686
  * Play a {@link DisTubeStream}
686
687
  * @param dtStream - DisTubeStream
687
688
  */
688
- play(dtStream) {
689
- if (!checkEncryptionLibraries()) {
689
+ async play(dtStream) {
690
+ if (!await checkEncryptionLibraries()) {
690
691
  dtStream.kill();
691
692
  throw new DisTubeError("ENCRYPTION_LIBRARIES_MISSING");
692
693
  }
@@ -696,11 +697,15 @@ var DisTubeVoice = class extends import_tiny_typed_emitter.TypedEmitter {
696
697
  this.emittedError = true;
697
698
  this.emit("error", error);
698
699
  });
699
- if (this.audioPlayer.state.status !== import_voice.AudioPlayerStatus.Paused) this.audioPlayer.play(dtStream.audioResource);
700
- this.stream?.kill();
700
+ if (this.audioPlayer.state.status !== import_voice.AudioPlayerStatus.Paused) {
701
+ this.audioPlayer.play(dtStream.audioResource);
702
+ this.stream?.kill();
703
+ dtStream.spawn();
704
+ } else if (!this.pausingStream) {
705
+ this.pausingStream = this.stream;
706
+ }
701
707
  this.stream = dtStream;
702
708
  this.volume = this.#volume;
703
- dtStream.spawn();
704
709
  }
705
710
  set volume(volume) {
706
711
  if (typeof volume !== "number" || isNaN(volume)) {
@@ -732,6 +737,9 @@ var DisTubeVoice = class extends import_tiny_typed_emitter.TypedEmitter {
732
737
  if (state.status !== import_voice.AudioPlayerStatus.Paused) return;
733
738
  if (this.stream?.audioResource && state.resource !== this.stream.audioResource) {
734
739
  this.audioPlayer.play(this.stream.audioResource);
740
+ this.stream.spawn();
741
+ this.pausingStream?.kill();
742
+ delete this.pausingStream;
735
743
  } else {
736
744
  this.audioPlayer.unpause();
737
745
  }
@@ -1489,7 +1497,7 @@ var QueueManager = class extends GuildIdManager {
1489
1497
  const dtStream = new DisTubeStream(stream.url, streamOptions);
1490
1498
  dtStream.on("debug", (data) => this.emit("ffmpegDebug" /* FFMPEG_DEBUG */, `[${queue.id}] ${data}`));
1491
1499
  this.debug(`[${queue.id}] Started playing: ${willPlaySong}`);
1492
- queue.voice.play(dtStream);
1500
+ await queue.voice.play(dtStream);
1493
1501
  if (emitPlaySong) this.emit("playSong" /* PLAY_SONG */, queue, song);
1494
1502
  } catch (e) {
1495
1503
  this.#handlePlayingError(queue, e);
@@ -1691,21 +1699,31 @@ var Queue = class extends DisTubeBase {
1691
1699
  * Pause the guild stream
1692
1700
  * @returns The guild queue
1693
1701
  */
1694
- pause() {
1695
- if (this.paused) throw new DisTubeError("PAUSED");
1696
- this.paused = true;
1697
- this.voice.pause();
1698
- return this;
1702
+ async pause() {
1703
+ await this._taskQueue.queuing();
1704
+ try {
1705
+ if (this.paused) throw new DisTubeError("PAUSED");
1706
+ this.paused = true;
1707
+ this.voice.pause();
1708
+ return this;
1709
+ } finally {
1710
+ this._taskQueue.resolve();
1711
+ }
1699
1712
  }
1700
1713
  /**
1701
1714
  * Resume the guild stream
1702
1715
  * @returns The guild queue
1703
1716
  */
1704
- resume() {
1705
- if (!this.paused) throw new DisTubeError("RESUMED");
1706
- this.paused = false;
1707
- this.voice.unpause();
1708
- return this;
1717
+ async resume() {
1718
+ await this._taskQueue.queuing();
1719
+ try {
1720
+ if (!this.paused) throw new DisTubeError("RESUMED");
1721
+ this.paused = false;
1722
+ this.voice.unpause();
1723
+ return this;
1724
+ } finally {
1725
+ this._taskQueue.resolve();
1726
+ }
1709
1727
  }
1710
1728
  /**
1711
1729
  * Set the guild stream's volume
@@ -2067,10 +2085,10 @@ function isNsfwChannel(channel) {
2067
2085
  }
2068
2086
  __name(isNsfwChannel, "isNsfwChannel");
2069
2087
  var isTruthy = /* @__PURE__ */ __name((x) => Boolean(x), "isTruthy");
2070
- var checkEncryptionLibraries = /* @__PURE__ */ __name(() => {
2088
+ var checkEncryptionLibraries = /* @__PURE__ */ __name(async () => {
2071
2089
  for (const lib of ["sodium-native", "sodium", "libsodium-wrappers", "tweetnacl"]) {
2072
2090
  try {
2073
- require(lib);
2091
+ await import(lib);
2074
2092
  return true;
2075
2093
  } catch {
2076
2094
  }
@@ -2467,7 +2485,7 @@ ${e.message}`;
2467
2485
  };
2468
2486
 
2469
2487
  // src/index.ts
2470
- var version = "5.0.3";
2488
+ var version = "5.0.5";
2471
2489
  // Annotate the CommonJS export names for ESM import in node:
2472
2490
  0 && (module.exports = {
2473
2491
  BaseManager,