distube 3.3.1 → 4.0.0-dev.2

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.
Files changed (114) hide show
  1. package/README.md +6 -8
  2. package/dist/DisTube.d.ts +13 -557
  3. package/dist/DisTube.d.ts.map +1 -1
  4. package/dist/DisTube.js +38 -639
  5. package/dist/DisTube.js.map +1 -1
  6. package/dist/constant.d.ts +0 -101
  7. package/dist/constant.d.ts.map +1 -1
  8. package/dist/constant.js +0 -101
  9. package/dist/constant.js.map +1 -1
  10. package/dist/core/DisTubeBase.d.ts +0 -40
  11. package/dist/core/DisTubeBase.d.ts.map +1 -1
  12. package/dist/core/DisTubeBase.js +0 -44
  13. package/dist/core/DisTubeBase.js.map +1 -1
  14. package/dist/core/DisTubeHandler.d.ts +2 -89
  15. package/dist/core/DisTubeHandler.d.ts.map +1 -1
  16. package/dist/core/DisTubeHandler.js +14 -124
  17. package/dist/core/DisTubeHandler.js.map +1 -1
  18. package/dist/core/DisTubeOptions.d.ts +0 -2
  19. package/dist/core/DisTubeOptions.d.ts.map +1 -1
  20. package/dist/core/DisTubeOptions.js +0 -13
  21. package/dist/core/DisTubeOptions.js.map +1 -1
  22. package/dist/core/DisTubeStream.d.ts +0 -33
  23. package/dist/core/DisTubeStream.d.ts.map +1 -1
  24. package/dist/core/DisTubeStream.js +0 -36
  25. package/dist/core/DisTubeStream.js.map +1 -1
  26. package/dist/core/manager/BaseManager.d.ts +1 -16
  27. package/dist/core/manager/BaseManager.d.ts.map +1 -1
  28. package/dist/core/manager/BaseManager.js +2 -28
  29. package/dist/core/manager/BaseManager.js.map +1 -1
  30. package/dist/core/manager/FilterManager.d.ts +16 -0
  31. package/dist/core/manager/FilterManager.d.ts.map +1 -0
  32. package/dist/core/manager/FilterManager.js +88 -0
  33. package/dist/core/manager/FilterManager.js.map +1 -0
  34. package/dist/core/manager/GuildIdManager.d.ts +9 -0
  35. package/dist/core/manager/GuildIdManager.d.ts.map +1 -0
  36. package/dist/core/manager/GuildIdManager.js +25 -0
  37. package/dist/core/manager/GuildIdManager.js.map +1 -0
  38. package/dist/core/manager/QueueManager.d.ts +4 -26
  39. package/dist/core/manager/QueueManager.d.ts.map +1 -1
  40. package/dist/core/manager/QueueManager.js +27 -48
  41. package/dist/core/manager/QueueManager.js.map +1 -1
  42. package/dist/core/manager/index.d.ts +2 -0
  43. package/dist/core/manager/index.d.ts.map +1 -1
  44. package/dist/core/manager/index.js +2 -0
  45. package/dist/core/manager/index.js.map +1 -1
  46. package/dist/core/voice/DisTubeVoice.d.ts +0 -50
  47. package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
  48. package/dist/core/voice/DisTubeVoice.js +9 -71
  49. package/dist/core/voice/DisTubeVoice.js.map +1 -1
  50. package/dist/core/voice/DisTubeVoiceManager.d.ts +2 -33
  51. package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -1
  52. package/dist/core/voice/DisTubeVoiceManager.js +1 -32
  53. package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
  54. package/dist/core/voice/index.d.ts +0 -1
  55. package/dist/core/voice/index.d.ts.map +1 -1
  56. package/dist/core/voice/index.js +0 -1
  57. package/dist/core/voice/index.js.map +1 -1
  58. package/dist/plugin/index.d.ts +0 -1
  59. package/dist/plugin/index.d.ts.map +1 -1
  60. package/dist/plugin/index.js +0 -1
  61. package/dist/plugin/index.js.map +1 -1
  62. package/dist/struct/CustomPlugin.d.ts +0 -41
  63. package/dist/struct/CustomPlugin.d.ts.map +1 -1
  64. package/dist/struct/CustomPlugin.js +0 -34
  65. package/dist/struct/CustomPlugin.js.map +1 -1
  66. package/dist/struct/DisTubeError.d.ts +0 -1
  67. package/dist/struct/DisTubeError.d.ts.map +1 -1
  68. package/dist/struct/DisTubeError.js +0 -2
  69. package/dist/struct/DisTubeError.js.map +1 -1
  70. package/dist/struct/ExtractorPlugin.d.ts +0 -32
  71. package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
  72. package/dist/struct/ExtractorPlugin.js +0 -23
  73. package/dist/struct/ExtractorPlugin.js.map +1 -1
  74. package/dist/struct/Playlist.d.ts +0 -36
  75. package/dist/struct/Playlist.d.ts.map +1 -1
  76. package/dist/struct/Playlist.js +3 -54
  77. package/dist/struct/Playlist.js.map +1 -1
  78. package/dist/struct/Plugin.d.ts +0 -58
  79. package/dist/struct/Plugin.d.ts.map +1 -1
  80. package/dist/struct/Plugin.js +0 -62
  81. package/dist/struct/Plugin.js.map +1 -1
  82. package/dist/struct/Queue.d.ts +10 -177
  83. package/dist/struct/Queue.d.ts.map +1 -1
  84. package/dist/struct/Queue.js +49 -256
  85. package/dist/struct/Queue.js.map +1 -1
  86. package/dist/struct/SearchResult.d.ts +0 -8
  87. package/dist/struct/SearchResult.d.ts.map +1 -1
  88. package/dist/struct/SearchResult.js +0 -47
  89. package/dist/struct/SearchResult.js.map +1 -1
  90. package/dist/struct/Song.d.ts +0 -38
  91. package/dist/struct/Song.d.ts.map +1 -1
  92. package/dist/struct/Song.js +3 -122
  93. package/dist/struct/Song.js.map +1 -1
  94. package/dist/struct/TaskQueue.d.ts +0 -20
  95. package/dist/struct/TaskQueue.d.ts.map +1 -1
  96. package/dist/struct/TaskQueue.js +0 -25
  97. package/dist/struct/TaskQueue.js.map +1 -1
  98. package/dist/tsconfig.tsbuildinfo +1 -1
  99. package/dist/type.d.ts +6 -75
  100. package/dist/type.d.ts.map +1 -1
  101. package/dist/type.js.map +1 -1
  102. package/dist/util.d.ts +1 -30
  103. package/dist/util.d.ts.map +1 -1
  104. package/dist/util.js +16 -59
  105. package/dist/util.js.map +1 -1
  106. package/package.json +22 -14
  107. package/dist/core/voice/DJSAdapter.d.ts +0 -4
  108. package/dist/core/voice/DJSAdapter.d.ts.map +0 -1
  109. package/dist/core/voice/DJSAdapter.js +0 -58
  110. package/dist/core/voice/DJSAdapter.js.map +0 -1
  111. package/dist/plugin/youtube-dl.d.ts +0 -12
  112. package/dist/plugin/youtube-dl.d.ts.map +0 -1
  113. package/dist/plugin/youtube-dl.js +0 -70
  114. package/dist/plugin/youtube-dl.js.map +0 -1
@@ -9,34 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.QueueManager = void 0;
10
10
  const _1 = require(".");
11
11
  const __1 = require("../..");
12
- /**
13
- * Queue manager
14
- * @extends BaseManager
15
- */
16
- class QueueManager extends _1.BaseManager {
12
+ class QueueManager extends _1.GuildIdManager {
17
13
  constructor() {
18
14
  super(...arguments);
19
15
  _QueueManager_instances.add(this);
20
16
  }
21
- /**
22
- * Collection of {@link Queue}.
23
- * @name QueueManager#collection
24
- * @type {Discord.Collection<string, Queue>}
25
- */
26
- /**
27
- * Create a {@link Queue}
28
- * @private
29
- * @param {Discord.BaseGuildVoiceChannel} channel A voice channel
30
- * @param {Song|Song[]} song First song
31
- * @param {Discord.BaseGuildTextChannel} textChannel Default text channel
32
- * @returns {Promise<Queue|true>} Returns `true` if encounter an error
33
- */
34
17
  async create(channel, song, textChannel) {
35
18
  if (this.has(channel.guild.id))
36
19
  throw new __1.DisTubeError("QUEUE_EXIST");
37
20
  const voice = this.voices.create(channel);
38
21
  const queue = new __1.Queue(this.distube, voice, song, textChannel);
39
- await queue.taskQueue.queuing();
22
+ await queue._taskQueue.queuing();
40
23
  try {
41
24
  await voice.join();
42
25
  __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_voiceEventHandler).call(this, queue);
@@ -46,15 +29,18 @@ class QueueManager extends _1.BaseManager {
46
29
  return err || queue;
47
30
  }
48
31
  finally {
49
- queue.taskQueue.resolve();
32
+ queue._taskQueue.resolve();
50
33
  }
51
34
  }
52
- /**
53
- * Play a song on voice connection
54
- * @private
55
- * @param {Queue} queue The guild queue
56
- * @returns {Promise<boolean>} error?
57
- */
35
+ createStream(queue) {
36
+ const { duration, formats, isLive, source, streamURL } = queue.songs[0];
37
+ const ffmpegArgs = queue.filters.size ? ["-af", queue.filters.values.join(",")] : undefined;
38
+ const seek = duration ? queue.beginTime : undefined;
39
+ const streamOptions = { ffmpegArgs, seek, isLive };
40
+ if (source === "youtube")
41
+ return __1.DisTubeStream.YouTube(formats, streamOptions);
42
+ return __1.DisTubeStream.DirectLink(streamURL, streamOptions);
43
+ }
58
44
  async playSong(queue) {
59
45
  if (!queue)
60
46
  return true;
@@ -80,7 +66,7 @@ class QueueManager extends _1.BaseManager {
80
66
  }
81
67
  }
82
68
  }
83
- const stream = this.handler.createStream(queue);
69
+ const stream = this.createStream(queue);
84
70
  queue.voice.play(stream);
85
71
  song.streamURL = stream.url;
86
72
  if (queue.stopped)
@@ -97,9 +83,9 @@ class QueueManager extends _1.BaseManager {
97
83
  }
98
84
  exports.QueueManager = QueueManager;
99
85
  _QueueManager_instances = new WeakSet(), _QueueManager_voiceEventHandler = function _QueueManager_voiceEventHandler(queue) {
100
- queue.listeners = {
86
+ queue._listeners = {
101
87
  disconnect: error => {
102
- queue.delete();
88
+ queue.remove();
103
89
  this.emit("disconnect", queue);
104
90
  if (error)
105
91
  this.emitError(error, queue.textChannel);
@@ -107,31 +93,24 @@ _QueueManager_instances = new WeakSet(), _QueueManager_voiceEventHandler = funct
107
93
  error: error => __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_handlePlayingError).call(this, queue, error),
108
94
  finish: () => __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_handleSongFinish).call(this, queue),
109
95
  };
110
- for (const event of Object.keys(queue.listeners)) {
111
- queue.voice.on(event, queue.listeners[event]);
96
+ for (const event of Object.keys(queue._listeners)) {
97
+ queue.voice.on(event, queue._listeners[event]);
112
98
  }
113
- }, _QueueManager_handleSongFinish =
114
- /**
115
- * Handle the queue when a Song finish
116
- * @private
117
- * @param {Queue} queue queue
118
- * @returns {Promise<void>}
119
- */
120
- async function _QueueManager_handleSongFinish(queue) {
99
+ }, _QueueManager_handleSongFinish = async function _QueueManager_handleSongFinish(queue) {
121
100
  this.emit("finishSong", queue, queue.songs[0]);
122
- await queue.taskQueue.queuing();
101
+ await queue._taskQueue.queuing();
123
102
  try {
124
103
  if (queue.stopped)
125
104
  return;
126
- if (queue.repeatMode === __1.RepeatMode.QUEUE && !queue.prev)
105
+ if (queue.repeatMode === __1.RepeatMode.QUEUE && !queue._prev)
127
106
  queue.songs.push(queue.songs[0]);
128
- if (queue.prev) {
107
+ if (queue._prev) {
129
108
  if (queue.repeatMode === __1.RepeatMode.QUEUE)
130
109
  queue.songs.unshift(queue.songs.pop());
131
110
  else
132
111
  queue.songs.unshift(queue.previousSongs.pop());
133
112
  }
134
- if (queue.songs.length <= 1 && (queue.next || queue.repeatMode === __1.RepeatMode.DISABLED)) {
113
+ if (queue.songs.length <= 1 && (queue._next || queue.repeatMode === __1.RepeatMode.DISABLED)) {
135
114
  if (queue.autoplay) {
136
115
  try {
137
116
  await queue.addRelatedSong();
@@ -145,12 +124,12 @@ async function _QueueManager_handleSongFinish(queue) {
145
124
  queue.voice.leave();
146
125
  if (!queue.autoplay)
147
126
  this.emit("finish", queue);
148
- queue.delete();
127
+ queue.remove();
149
128
  return;
150
129
  }
151
130
  }
152
131
  const emitPlaySong = __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_emitPlaySong).call(this, queue);
153
- if (!queue.prev && (queue.repeatMode !== __1.RepeatMode.SONG || queue.next)) {
132
+ if (!queue._prev && (queue.repeatMode !== __1.RepeatMode.SONG || queue._next)) {
154
133
  const prev = queue.songs.shift();
155
134
  delete prev.formats;
156
135
  delete prev.streamURL;
@@ -159,14 +138,14 @@ async function _QueueManager_handleSongFinish(queue) {
159
138
  else
160
139
  queue.previousSongs.push({ id: prev.id });
161
140
  }
162
- queue.next = queue.prev = false;
141
+ queue._next = queue._prev = false;
163
142
  queue.beginTime = 0;
164
143
  const err = await this.playSong(queue);
165
144
  if (!err && emitPlaySong)
166
145
  this.emit("playSong", queue, queue.songs[0]);
167
146
  }
168
147
  finally {
169
- queue.taskQueue.resolve();
148
+ queue._taskQueue.resolve();
170
149
  }
171
150
  }, _QueueManager_handlePlayingError = function _QueueManager_handlePlayingError(queue, error) {
172
151
  const song = queue.songs.shift();
@@ -187,7 +166,7 @@ async function _QueueManager_handleSongFinish(queue) {
187
166
  }
188
167
  }, _QueueManager_emitPlaySong = function _QueueManager_emitPlaySong(queue) {
189
168
  return (!this.options.emitNewSongOnly ||
190
- (queue.repeatMode === __1.RepeatMode.SONG && queue.next) ||
169
+ (queue.repeatMode === __1.RepeatMode.SONG && queue._next) ||
191
170
  (queue.repeatMode !== __1.RepeatMode.SONG && queue.songs[0]?.id !== queue.songs[1]?.id));
192
171
  };
193
172
  //# sourceMappingURL=QueueManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wBAAgC;AAChC,6BAAwD;AAIxD;;;GAGG;AACH,MAAa,YAAa,SAAQ,cAAkB;IAApD;;;IAqLA,CAAC;IApLC;;;;OAIG;IACH;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,OAA0B,EAC1B,IAAmB,EACnB,WAAmC;QAEnC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,aAAa,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,SAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI;YACF,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,uBAAA,IAAI,gEAAmB,MAAvB,IAAI,EAAoB,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CA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,CAAC,OAAO,EAAE,CAAC;KAC3B;AACH,CAAC,+EAOmB,KAAY,EAAE,KAAY;IAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAU,CAAC;IACzC,IAAI;QACF,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;QAC5B,KAAK,CAAC,OAAO,GAAG,GAAG,KAAK,CAAC,OAAO,SAAS,IAAI,CAAC,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC;KACxE;IAAC,MAAM,GAAE;IACV,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC5B,IAAI,CAAC,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,KAAK,CAAC,IAAI,EAAE,CAAC;KACd;AACH,CAAC,mEA+Ca,KAAY;IACxB,OAAO,CACL,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;QAC7B,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;QACpD,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACpF,CAAC;AACJ,CAAC","sourcesContent":["import { BaseManager } from \".\";\nimport { DisTubeError, Queue, RepeatMode } from \"../..\";\nimport type { DisTubeVoiceEvents, Song } from \"../..\";\nimport type { GuildTextBasedChannel, VoiceBasedChannel } from \"discord.js\";\n\n/**\n * Queue manager\n * @extends BaseManager\n */\nexport class QueueManager extends BaseManager<Queue> {\n /**\n * Collection of {@link Queue}.\n * @name QueueManager#collection\n * @type {Discord.Collection<string, Queue>}\n */\n /**\n * Create a {@link Queue}\n * @private\n * @param {Discord.BaseGuildVoiceChannel} channel A voice channel\n * @param {Song|Song[]} song First song\n * @param {Discord.BaseGuildTextChannel} textChannel Default text channel\n * @returns {Promise<Queue|true>} Returns `true` if encounter an error\n */\n async create(\n channel: VoiceBasedChannel,\n song: Song[] | Song,\n textChannel?: GuildTextBasedChannel,\n ): Promise<Queue | true> {\n if (this.has(channel.guild.id)) throw new DisTubeError(\"QUEUE_EXIST\");\n const voice = this.voices.create(channel);\n const queue = new Queue(this.distube, voice, song, textChannel);\n await queue.taskQueue.queuing();\n try {\n await voice.join();\n this.#voiceEventHandler(queue);\n this.add(queue.id, queue);\n this.emit(\"initQueue\", queue);\n const err = await this.playSong(queue);\n return err || queue;\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Get a Queue from this QueueManager.\n * @method get\n * @memberof QueueManager#\n * @param {GuildIdResolvable} queue Resolvable thing from a guild\n * @returns {Queue?}\n */\n /**\n * Listen to DisTubeVoice events and handle the Queue\n * @private\n * @param {Queue} queue Queue\n */\n #voiceEventHandler(queue: Queue) {\n queue.listeners = {\n disconnect: error => {\n queue.delete();\n this.emit(\"disconnect\", queue);\n if (error) this.emitError(error, queue.textChannel);\n },\n error: error => this.#handlePlayingError(queue, error),\n finish: () => this.#handleSongFinish(queue),\n };\n for (const event of Object.keys(queue.listeners) as (keyof DisTubeVoiceEvents)[]) {\n queue.voice.on(event, queue.listeners[event]);\n }\n }\n /**\n * Handle the queue when a Song finish\n * @private\n * @param {Queue} queue queue\n * @returns {Promise<void>}\n */\n async #handleSongFinish(queue: Queue): Promise<void> {\n this.emit(\"finishSong\", queue, queue.songs[0]);\n await queue.taskQueue.queuing();\n try {\n if (queue.stopped) return;\n if (queue.repeatMode === RepeatMode.QUEUE && !queue.prev) queue.songs.push(queue.songs[0]);\n if (queue.prev) {\n if (queue.repeatMode === RepeatMode.QUEUE) queue.songs.unshift(queue.songs.pop() as Song);\n else queue.songs.unshift(queue.previousSongs.pop() as Song);\n }\n if (queue.songs.length <= 1 && (queue.next || queue.repeatMode === RepeatMode.DISABLED)) {\n if (queue.autoplay) {\n try {\n await queue.addRelatedSong();\n } catch {\n this.emit(\"noRelated\", queue);\n }\n }\n if (queue.songs.length <= 1) {\n if (this.options.leaveOnFinish) queue.voice.leave();\n if (!queue.autoplay) this.emit(\"finish\", queue);\n queue.delete();\n return;\n }\n }\n const emitPlaySong = this.#emitPlaySong(queue);\n if (!queue.prev && (queue.repeatMode !== RepeatMode.SONG || queue.next)) {\n const prev = queue.songs.shift() as Song;\n delete prev.formats;\n delete prev.streamURL;\n if (this.options.savePreviousSongs) queue.previousSongs.push(prev);\n else queue.previousSongs.push({ id: prev.id } as Song);\n }\n queue.next = queue.prev = false;\n queue.beginTime = 0;\n const err = await this.playSong(queue);\n if (!err && emitPlaySong) this.emit(\"playSong\", queue, queue.songs[0]);\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Handle error while playing\n * @private\n * @param {Queue} queue queue\n * @param {Error} error error\n */\n #handlePlayingError(queue: Queue, error: Error) {\n const song = queue.songs.shift() as Song;\n try {\n error.name = \"PlayingError\";\n error.message = `${error.message}\\nId: ${song.id}\\nName: ${song.name}`;\n } catch {}\n this.emitError(error, queue.textChannel);\n if (queue.songs.length > 0) {\n this.playSong(queue).then(e => {\n if (!e) this.emit(\"playSong\", queue, queue.songs[0]);\n });\n } else {\n queue.stop();\n }\n }\n\n /**\n * Play a song on voice connection\n * @private\n * @param {Queue} queue The guild queue\n * @returns {Promise<boolean>} error?\n */\n async playSong(queue: Queue): Promise<boolean> {\n if (!queue) return true;\n if (!queue.songs.length) {\n queue.stop();\n return true;\n }\n if (queue.stopped) return false;\n const song = queue.songs[0];\n try {\n const { url, source, formats, streamURL } = song;\n if (source === \"youtube\" && !formats) song._patchYouTube(await this.handler.getYouTubeInfo(url));\n if (source !== \"youtube\" && !streamURL) {\n for (const plugin of [...this.distube.extractorPlugins, ...this.distube.customPlugins]) {\n if (await plugin.validate(url)) {\n const info = [plugin.getStreamURL(url), plugin.getRelatedSongs(url)] as const;\n const result = await Promise.all(info);\n song.streamURL = result[0];\n song.related = result[1];\n break;\n }\n }\n }\n const stream = this.handler.createStream(queue);\n queue.voice.play(stream);\n song.streamURL = stream.url;\n if (queue.stopped) queue.stop();\n else if (queue.paused) queue.voice.pause();\n return false;\n } catch (e: any) {\n this.#handlePlayingError(queue, e);\n return true;\n }\n }\n /**\n * Whether or not emit playSong event\n * @param {Queue} queue Queue\n * @private\n * @returns {boolean}\n */\n #emitPlaySong(queue: Queue): boolean {\n return (\n !this.options.emitNewSongOnly ||\n (queue.repeatMode === RepeatMode.SONG && queue.next) ||\n (queue.repeatMode !== RepeatMode.SONG && queue.songs[0]?.id !== queue.songs[1]?.id)\n );\n }\n}\n"]}
1
+ {"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wBAAmC;AACnC,6BAAuE;AAQvE,MAAa,YAAa,SAAQ,iBAAqB;IAAvD;;;IAmMA,CAAC;IArLC,KAAK,CAAC,MAAM,CACV,OAA0B,EAC1B,IAAmB,EACnB,WAAmC;QAEnC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,aAAa,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,SAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC,UAAU,CAAC,OAAO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AAW,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC5B,IAAI,CAAC,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,KAAK,CAAC,IAAI,EAAE,CAAC;KACd;AACH,CAAC,mEA6Da,KAAY;IACxB,OAAO,CACL,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;QAC7B,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC;QACrD,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACpF,CAAC;AACJ,CAAC","sourcesContent":["import { GuildIdManager } from \".\";\nimport { DisTubeError, DisTubeStream, Queue, RepeatMode } from \"../..\";\nimport type { DisTubeVoiceEvents, Song } from \"../..\";\nimport type { GuildTextBasedChannel, VoiceBasedChannel } from \"discord.js\";\n\n/**\n * Queue manager\n * @extends GuildIdManager\n */\nexport class QueueManager extends GuildIdManager<Queue> {\n /**\n * Collection of {@link Queue}.\n * @name QueueManager#collection\n * @type {Discord.Collection<string, Queue>}\n */\n /**\n * Create a {@link Queue}\n * @private\n * @param {Discord.BaseGuildVoiceChannel} channel A voice channel\n * @param {Song|Song[]} song First song\n * @param {Discord.BaseGuildTextChannel} textChannel Default text channel\n * @returns {Promise<Queue|true>} Returns `true` if encounter an error\n */\n async create(\n channel: VoiceBasedChannel,\n song: Song[] | Song,\n textChannel?: GuildTextBasedChannel,\n ): Promise<Queue | true> {\n if (this.has(channel.guild.id)) throw new DisTubeError(\"QUEUE_EXIST\");\n const voice = this.voices.create(channel);\n const queue = new Queue(this.distube, voice, song, textChannel);\n await queue._taskQueue.queuing();\n try {\n await voice.join();\n this.#voiceEventHandler(queue);\n this.add(queue.id, queue);\n this.emit(\"initQueue\", queue);\n const err = await this.playSong(queue);\n return err || queue;\n } finally {\n queue._taskQueue.resolve();\n }\n }\n /**\n * Get a Queue from this QueueManager.\n * @method get\n * @memberof QueueManager#\n * @param {GuildIdResolvable} guild Resolvable thing from a guild\n * @returns {Queue?}\n */\n /**\n * Listen to DisTubeVoice events and handle the Queue\n * @private\n * @param {Queue} queue Queue\n */\n #voiceEventHandler(queue: Queue) {\n queue._listeners = {\n disconnect: error => {\n queue.remove();\n this.emit(\"disconnect\", queue);\n if (error) this.emitError(error, queue.textChannel);\n },\n error: error => this.#handlePlayingError(queue, error),\n finish: () => this.#handleSongFinish(queue),\n };\n for (const event of Object.keys(queue._listeners) as (keyof DisTubeVoiceEvents)[]) {\n queue.voice.on(event, queue._listeners[event]);\n }\n }\n /**\n * Handle the queue when a Song finish\n * @private\n * @param {Queue} queue queue\n * @returns {Promise<void>}\n */\n async #handleSongFinish(queue: Queue): Promise<void> {\n this.emit(\"finishSong\", queue, queue.songs[0]);\n await queue._taskQueue.queuing();\n try {\n if (queue.stopped) return;\n if (queue.repeatMode === RepeatMode.QUEUE && !queue._prev) queue.songs.push(queue.songs[0]);\n if (queue._prev) {\n if (queue.repeatMode === RepeatMode.QUEUE) queue.songs.unshift(queue.songs.pop() as Song);\n else queue.songs.unshift(queue.previousSongs.pop() as Song);\n }\n if (queue.songs.length <= 1 && (queue._next || queue.repeatMode === RepeatMode.DISABLED)) {\n if (queue.autoplay) {\n try {\n await queue.addRelatedSong();\n } catch {\n this.emit(\"noRelated\", queue);\n }\n }\n if (queue.songs.length <= 1) {\n if (this.options.leaveOnFinish) queue.voice.leave();\n if (!queue.autoplay) this.emit(\"finish\", queue);\n queue.remove();\n return;\n }\n }\n const emitPlaySong = this.#emitPlaySong(queue);\n if (!queue._prev && (queue.repeatMode !== RepeatMode.SONG || queue._next)) {\n const prev = queue.songs.shift() as Song;\n delete prev.formats;\n delete prev.streamURL;\n if (this.options.savePreviousSongs) queue.previousSongs.push(prev);\n else queue.previousSongs.push({ id: prev.id } as Song);\n }\n queue._next = queue._prev = false;\n queue.beginTime = 0;\n const err = await this.playSong(queue);\n if (!err && emitPlaySong) this.emit(\"playSong\", queue, queue.songs[0]);\n } finally {\n queue._taskQueue.resolve();\n }\n }\n /**\n * Handle error while playing\n * @private\n * @param {Queue} queue queue\n * @param {Error} error error\n */\n #handlePlayingError(queue: Queue, error: Error) {\n const song = queue.songs.shift() as Song;\n try {\n error.name = \"PlayingError\";\n error.message = `${error.message}\\nId: ${song.id}\\nName: ${song.name}`;\n } catch {}\n this.emitError(error, queue.textChannel);\n if (queue.songs.length > 0) {\n this.playSong(queue).then(e => {\n if (!e) this.emit(\"playSong\", queue, queue.songs[0]);\n });\n } else {\n queue.stop();\n }\n }\n\n /**\n * Create a ytdl stream\n * @param {Queue} queue Queue\n * @returns {DisTubeStream}\n */\n createStream(queue: Queue): DisTubeStream {\n const { duration, formats, isLive, source, streamURL } = queue.songs[0];\n const ffmpegArgs = queue.filters.size ? [\"-af\", queue.filters.values.join(\",\")] : undefined;\n const seek = duration ? queue.beginTime : undefined;\n const streamOptions = { ffmpegArgs, seek, isLive };\n if (source === \"youtube\") return DisTubeStream.YouTube(formats, streamOptions);\n return DisTubeStream.DirectLink(streamURL as string, streamOptions);\n }\n\n /**\n * Play a song on voice connection\n * @private\n * @param {Queue} queue The guild queue\n * @returns {Promise<boolean>} error?\n */\n async playSong(queue: Queue): Promise<boolean> {\n if (!queue) return true;\n if (!queue.songs.length) {\n queue.stop();\n return true;\n }\n if (queue.stopped) return false;\n const song = queue.songs[0];\n try {\n const { url, source, formats, streamURL } = song;\n if (source === \"youtube\" && !formats) song._patchYouTube(await this.handler.getYouTubeInfo(url));\n if (source !== \"youtube\" && !streamURL) {\n for (const plugin of [...this.distube.extractorPlugins, ...this.distube.customPlugins]) {\n if (await plugin.validate(url)) {\n const info = [plugin.getStreamURL(url), plugin.getRelatedSongs(url)] as const;\n const result = await Promise.all(info);\n song.streamURL = result[0];\n song.related = result[1];\n break;\n }\n }\n }\n const stream = this.createStream(queue);\n queue.voice.play(stream);\n song.streamURL = stream.url;\n if (queue.stopped) queue.stop();\n else if (queue.paused) queue.voice.pause();\n return false;\n } catch (e: any) {\n this.#handlePlayingError(queue, e);\n return true;\n }\n }\n /**\n * Whether or not emit playSong event\n * @param {Queue} queue Queue\n * @private\n * @returns {boolean}\n */\n #emitPlaySong(queue: Queue): boolean {\n return (\n !this.options.emitNewSongOnly ||\n (queue.repeatMode === RepeatMode.SONG && queue._next) ||\n (queue.repeatMode !== RepeatMode.SONG && queue.songs[0]?.id !== queue.songs[1]?.id)\n );\n }\n}\n"]}
@@ -1,3 +1,5 @@
1
1
  export * from "./BaseManager";
2
+ export * from "./GuildIdManager";
2
3
  export * from "./QueueManager";
4
+ export * from "./FilterManager";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
@@ -11,5 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./BaseManager"), exports);
14
+ __exportStar(require("./GuildIdManager"), exports);
14
15
  __exportStar(require("./QueueManager"), exports);
16
+ __exportStar(require("./FilterManager"), exports);
15
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B","sourcesContent":["export * from \"./BaseManager\";\nexport * from \"./QueueManager\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,mDAAiC;AACjC,iDAA+B;AAC/B,kDAAgC","sourcesContent":["export * from \"./BaseManager\";\nexport * from \"./GuildIdManager\";\nexport * from \"./QueueManager\";\nexport * from \"./FilterManager\";\n"]}
@@ -2,9 +2,6 @@ import { TypedEmitter } from "tiny-typed-emitter";
2
2
  import type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from "../..";
3
3
  import type { AudioPlayer, AudioResource, VoiceConnection } from "@discordjs/voice";
4
4
  import type { Snowflake, VoiceBasedChannel, VoiceState } from "discord.js";
5
- /**
6
- * Create a voice connection to the voice channel
7
- */
8
5
  export declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
9
6
  #private;
10
7
  readonly id: Snowflake;
@@ -17,66 +14,19 @@ export declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
17
14
  constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel);
18
15
  get channel(): VoiceBasedChannel;
19
16
  set channel(channel: VoiceBasedChannel);
20
- /**
21
- * Join a voice channel with this connection
22
- * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel
23
- * @private
24
- * @returns {Promise<DisTubeVoice>}
25
- */
26
17
  join(channel?: VoiceBasedChannel): Promise<DisTubeVoice>;
27
- /**
28
- * Leave the voice channel of this connection
29
- * @param {Error} [error] Optional, an error to emit with 'error' event.
30
- */
31
18
  leave(error?: Error): void;
32
- /**
33
- * Stop the playing stream
34
- * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
35
- * even if the {@link DisTubeVoice#audioResource} has silence padding frames.
36
- * @private
37
- */
38
19
  stop(force?: boolean): void;
39
- /**
40
- * Play a readable stream
41
- * @private
42
- * @param {DisTubeStream} stream Readable stream
43
- */
44
20
  play(stream: DisTubeStream): void;
45
21
  set volume(volume: number);
46
22
  get volume(): number;
47
- /**
48
- * Playback duration of the audio resource in seconds
49
- * @type {number}
50
- */
51
23
  get playbackDuration(): number;
52
24
  pause(): void;
53
25
  unpause(): void;
54
- /**
55
- * Whether the bot is self-deafened
56
- * @type {boolean}
57
- */
58
26
  get selfDeaf(): boolean;
59
- /**
60
- * Whether the bot is self-muted
61
- * @type {boolean}
62
- */
63
27
  get selfMute(): boolean;
64
- /**
65
- * Self-deafens/undeafens the bot.
66
- * @param {boolean} selfDeaf Whether or not the bot should be self-deafened
67
- * @returns {boolean} true if the voice state was successfully updated, otherwise false
68
- */
69
28
  setSelfDeaf(selfDeaf: boolean): boolean;
70
- /**
71
- * Self-mutes/unmutes the bot.
72
- * @param {boolean} selfMute Whether or not the bot should be self-muted
73
- * @returns {boolean} true if the voice state was successfully updated, otherwise false
74
- */
75
29
  setSelfMute(selfMute: boolean): boolean;
76
- /**
77
- * The voice state of this connection
78
- * @type {Discord.VoiceState?}
79
- */
80
30
  get voiceState(): VoiceState | undefined;
81
31
  }
82
32
  //# sourceMappingURL=DisTubeVoice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DisTubeVoice.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUlD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACp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EtB;IAMD,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IAcvC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IAavC,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAEvC;CACF"}
@@ -16,9 +16,6 @@ exports.DisTubeVoice = void 0;
16
16
  const tiny_typed_emitter_1 = require("tiny-typed-emitter");
17
17
  const __1 = require("../..");
18
18
  const voice_1 = require("@discordjs/voice");
19
- /**
20
- * Create a voice connection to the voice channel
21
- */
22
19
  class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
23
20
  constructor(voiceManager, channel) {
24
21
  super();
@@ -37,10 +34,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
37
34
  }
38
35
  this.id = channel.guild.id;
39
36
  this.channel = channel;
40
- /**
41
- * The voice manager that instantiated this connection
42
- * @type {DisTubeVoiceManager}
43
- */
44
37
  this.voices = voiceManager;
45
38
  this.voices.add(this.id, this);
46
39
  this.audioPlayer = (0, voice_1.createAudioPlayer)()
@@ -73,16 +66,9 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
73
66
  }
74
67
  })
75
68
  .on(voice_1.VoiceConnectionStatus.Destroyed, () => {
76
- this.leave();
77
- })
78
- // eslint-disable-next-line no-console
79
- .on("error", console.warn);
69
+ this.leave(new __1.DisTubeError("VOICE_RECONNECT_FAILED"));
70
+ });
80
71
  this.connection.subscribe(this.audioPlayer);
81
- /**
82
- * Get or set the volume percentage
83
- * @name DisTubeVoice#volume
84
- * @type {number}
85
- */
86
72
  }
87
73
  get channel() {
88
74
  return __classPrivateFieldGet(this, _DisTubeVoice_channel, "f");
@@ -94,14 +80,9 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
94
80
  if (channel.guild.id !== this.id)
95
81
  throw new __1.DisTubeError("VOICE_CHANGE_GUILD");
96
82
  this.connection = __classPrivateFieldGet(this, _DisTubeVoice_instances, "m", _DisTubeVoice_join).call(this, channel);
83
+ this.audioResource?.encoder?.setBitrate(channel.bitrate);
97
84
  __classPrivateFieldSet(this, _DisTubeVoice_channel, channel, "f");
98
85
  }
99
- /**
100
- * Join a voice channel with this connection
101
- * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel
102
- * @private
103
- * @returns {Promise<DisTubeVoice>}
104
- */
105
86
  async join(channel) {
106
87
  const TIMEOUT = 30e3;
107
88
  if (channel) {
@@ -114,17 +95,11 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
114
95
  if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
115
96
  this.connection.destroy();
116
97
  }
117
- this.voices.delete(this.id);
118
- if (this.voiceState?.connection)
119
- throw new __1.DisTubeError("VOICE_DEPRECATED_CONNECTION");
98
+ this.voices.remove(this.id);
120
99
  throw new __1.DisTubeError("VOICE_CONNECT_FAILED", TIMEOUT / 1e3);
121
100
  }
122
101
  return this;
123
102
  }
124
- /**
125
- * Leave the voice channel of this connection
126
- * @param {Error} [error] Optional, an error to emit with 'error' event.
127
- */
128
103
  leave(error) {
129
104
  this.stop(true);
130
105
  if (!this.isDisconnected) {
@@ -133,22 +108,11 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
133
108
  }
134
109
  if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed)
135
110
  this.connection.destroy();
136
- this.voices.delete(this.id);
137
- }
138
- /**
139
- * Stop the playing stream
140
- * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
141
- * even if the {@link DisTubeVoice#audioResource} has silence padding frames.
142
- * @private
143
- */
111
+ this.voices.remove(this.id);
112
+ }
144
113
  stop(force = false) {
145
114
  this.audioPlayer.stop(force);
146
115
  }
147
- /**
148
- * Play a readable stream
149
- * @private
150
- * @param {DisTubeStream} stream Readable stream
151
- */
152
116
  play(stream) {
153
117
  this.emittedError = false;
154
118
  stream.stream.on("error", (error) => {
@@ -161,8 +125,8 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
161
125
  inputType: stream.type,
162
126
  inlineVolume: true,
163
127
  });
164
- // eslint-disable-next-line no-self-assign
165
- this.volume = this.volume;
128
+ this.volume = __classPrivateFieldGet(this, _DisTubeVoice_volume, "f");
129
+ this.audioResource.encoder?.setBitrate(this.channel.bitrate);
166
130
  this.audioPlayer.play(this.audioResource);
167
131
  }
168
132
  set volume(volume) {
@@ -178,10 +142,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
178
142
  get volume() {
179
143
  return __classPrivateFieldGet(this, _DisTubeVoice_volume, "f");
180
144
  }
181
- /**
182
- * Playback duration of the audio resource in seconds
183
- * @type {number}
184
- */
185
145
  get playbackDuration() {
186
146
  return (this.audioResource?.playbackDuration ?? 0) / 1000;
187
147
  }
@@ -191,25 +151,12 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
191
151
  unpause() {
192
152
  this.audioPlayer.unpause();
193
153
  }
194
- /**
195
- * Whether the bot is self-deafened
196
- * @type {boolean}
197
- */
198
154
  get selfDeaf() {
199
155
  return this.connection.joinConfig.selfDeaf;
200
156
  }
201
- /**
202
- * Whether the bot is self-muted
203
- * @type {boolean}
204
- */
205
157
  get selfMute() {
206
158
  return this.connection.joinConfig.selfMute;
207
159
  }
208
- /**
209
- * Self-deafens/undeafens the bot.
210
- * @param {boolean} selfDeaf Whether or not the bot should be self-deafened
211
- * @returns {boolean} true if the voice state was successfully updated, otherwise false
212
- */
213
160
  setSelfDeaf(selfDeaf) {
214
161
  if (typeof selfDeaf !== "boolean") {
215
162
  throw new __1.DisTubeError("INVALID_TYPE", "boolean", selfDeaf, "selfDeaf");
@@ -219,11 +166,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
219
166
  selfDeaf,
220
167
  });
221
168
  }
222
- /**
223
- * Self-mutes/unmutes the bot.
224
- * @param {boolean} selfMute Whether or not the bot should be self-muted
225
- * @returns {boolean} true if the voice state was successfully updated, otherwise false
226
- */
227
169
  setSelfMute(selfMute) {
228
170
  if (typeof selfMute !== "boolean") {
229
171
  throw new __1.DisTubeError("INVALID_TYPE", "boolean", selfMute, "selfMute");
@@ -233,10 +175,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
233
175
  selfMute,
234
176
  });
235
177
  }
236
- /**
237
- * The voice state of this connection
238
- * @type {Discord.VoiceState?}
239
- */
240
178
  get voiceState() {
241
179
  return this.channel?.guild?.me?.voice;
242
180
  }
@@ -246,7 +184,7 @@ _DisTubeVoice_channel = new WeakMap(), _DisTubeVoice_volume = new WeakMap(), _Di
246
184
  return (0, voice_1.joinVoiceChannel)({
247
185
  channelId: channel.id,
248
186
  guildId: this.id,
249
- adapterCreator: channel.guild.voiceAdapterCreator || (0, __1.createDiscordJSAdapter)(channel),
187
+ adapterCreator: channel.guild.voiceAdapterCreator,
250
188
  });
251
189
  };
252
190
  //# sourceMappingURL=DisTubeVoice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAkD;AAClD,6BAAmG;AACnG,4CAO0B;AAK1B;;GAEG;AACH,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAA0B;QACvE,KAAK,EAAE,CAAC;;QAJV,mBAAc,GAAG,KAAK,CAAC;QACvB,wCAA6B;QAC7B,+BAAU,GAAG,EAAC;QAGZ,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC,EAAE;YACrC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,uBAAuB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;SACrF;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,gBAAY,CAAC,YAAY,CAAC,CAAC;;gBAClD,MAAM,IAAI,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H,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC;IACxC,CAAC;CACF;AA/ND,oCA+NC;uKAnJO,OAA0B;IAC9B,OAAO,IAAA,wBAAgB,EAAC;QACtB,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,OAAO,EAAE,IAAI,CAAC,EAAE;QAChB,cAAc,EAAG,OAAO,CAAC,KAAK,CAAC,mBAA2B,IAAI,IAAA,0BAAsB,EAAC,OAAc,CAAC;KACrG,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, createDiscordJSAdapter, entersState, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, VoiceBasedChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n readonly id: Snowflake;\n readonly voices: DisTubeVoiceManager;\n readonly audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected = false;\n #channel!: VoiceBasedChannel;\n #volume = 100;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"channel\");\n }\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.id = channel.guild.id;\n this.channel = channel;\n /**\n * The voice manager that instantiated this connection\n * @type {DisTubeVoiceManager}\n */\n this.voices = voiceManager;\n this.voices.add(this.id, this);\n this.audioPlayer = createAudioPlayer()\n .on(AudioPlayerStatus.Idle, oldState => {\n if (oldState.status !== AudioPlayerStatus.Idle) {\n delete this.audioResource;\n this.emit(\"finish\");\n }\n })\n .on(\"error\", error => {\n if (this.emittedError) return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.connection\n .on(VoiceConnectionStatus.Disconnected, (_, newState) => {\n if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {\n entersState(this.connection, VoiceConnectionStatus.Connecting, 5e3).catch(() => {\n this.leave();\n });\n } else if (this.connection.rejoinAttempts < 5) {\n setTimeout(() => {\n this.connection.rejoin();\n }, (this.connection.rejoinAttempts + 1) * 5e3).unref();\n } else if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.leave(new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n }\n })\n .on(VoiceConnectionStatus.Destroyed, () => {\n this.leave();\n })\n // eslint-disable-next-line no-console\n .on(\"error\", console.warn);\n this.connection.subscribe(this.audioPlayer);\n /**\n * Get or set the volume percentage\n * @name DisTubeVoice#volume\n * @type {number}\n */\n }\n get channel() {\n return this.#channel;\n }\n set channel(channel: VoiceBasedChannel) {\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"DisTubeVoice#channel\");\n }\n if (channel.guild.id !== this.id) throw new DisTubeError(\"VOICE_CHANGE_GUILD\");\n this.connection = this.#join(channel);\n this.#channel = channel;\n }\n #join(channel: VoiceBasedChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: (channel.guild.voiceAdapterCreator as any) || createDiscordJSAdapter(channel as any),\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceBasedChannel): Promise<DisTubeVoice> {\n const TIMEOUT = 30e3;\n if (channel) {\n this.channel = channel;\n }\n try {\n await entersState(this.connection, VoiceConnectionStatus.Ready, TIMEOUT);\n } catch {\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.connection.destroy();\n }\n this.voices.delete(this.id);\n if ((this.voiceState as any)?.connection) throw new DisTubeError(\"VOICE_DEPRECATED_CONNECTION\");\n throw new DisTubeError(\"VOICE_CONNECT_FAILED\", TIMEOUT / 1e3);\n }\n return this;\n }\n /**\n * Leave the voice channel of this connection\n * @param {Error} [error] Optional, an error to emit with 'error' event.\n */\n leave(error?: Error) {\n this.stop(true);\n if (!this.isDisconnected) {\n this.emit(\"disconnect\", error);\n this.isDisconnected = true;\n }\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) this.connection.destroy();\n this.voices.delete(this.id);\n }\n /**\n * Stop the playing stream\n * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state\n * even if the {@link DisTubeVoice#audioResource} has silence padding frames.\n * @private\n */\n stop(force = false) {\n this.audioPlayer.stop(force);\n }\n /**\n * Play a readable stream\n * @private\n * @param {DisTubeStream} stream Readable stream\n */\n play(stream: DisTubeStream) {\n this.emittedError = false;\n stream.stream.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (this.emittedError || error.code === \"ERR_STREAM_PREMATURE_CLOSE\") return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.audioResource = createAudioResource(stream.stream, {\n inputType: stream.type,\n inlineVolume: true,\n });\n // eslint-disable-next-line no-self-assign\n this.volume = this.volume;\n this.audioPlayer.play(this.audioResource);\n }\n set volume(volume: number) {\n if (typeof volume !== \"number\" || isNaN(volume)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"number\", volume, \"volume\");\n }\n if (volume < 0) {\n throw new DisTubeError(\"NUMBER_COMPARE\", \"Volume\", \"bigger or equal to\", 0);\n }\n this.#volume = volume;\n this.audioResource?.volume?.setVolume(Math.pow(this.#volume / 100, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this.#volume;\n }\n /**\n * Playback duration of the audio resource in seconds\n * @type {number}\n */\n get playbackDuration() {\n return (this.audioResource?.playbackDuration ?? 0) / 1000;\n }\n pause() {\n this.audioPlayer.pause();\n }\n unpause() {\n this.audioPlayer.unpause();\n }\n /**\n * Whether the bot is self-deafened\n * @type {boolean}\n */\n get selfDeaf(): boolean {\n return this.connection.joinConfig.selfDeaf;\n }\n /**\n * Whether the bot is self-muted\n * @type {boolean}\n */\n get selfMute(): boolean {\n return this.connection.joinConfig.selfMute;\n }\n /**\n * Self-deafens/undeafens the bot.\n * @param {boolean} selfDeaf Whether or not the bot should be self-deafened\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfDeaf(selfDeaf: boolean): boolean {\n if (typeof selfDeaf !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfDeaf, \"selfDeaf\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfDeaf,\n });\n }\n /**\n * Self-mutes/unmutes the bot.\n * @param {boolean} selfMute Whether or not the bot should be self-muted\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfMute(selfMute: boolean): boolean {\n if (typeof selfMute !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfMute, \"selfMute\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfMute,\n });\n }\n /**\n * The voice state of this connection\n * @type {Discord.VoiceState?}\n */\n get voiceState(): VoiceState | undefined {\n return this.channel?.guild?.me?.voice;\n }\n}\n"]}
1
+ {"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAkD;AAClD,6BAA2E;AAC3E,4CAO0B;AAQ1B,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YA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CAAC;IAMD,WAAW,CAAC,QAAiB;QAC3B,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAKD,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC;IACxC,CAAC;CACF;AA5ND,oCA4NC;uKAjJO,OAA0B;IAC9B,OAAO,IAAA,wBAAgB,EAAC;QACtB,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,OAAO,EAAE,IAAI,CAAC,EAAE;QAChB,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,mBAA0B;KACzD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, entersState, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, VoiceBasedChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n readonly id: Snowflake;\n readonly voices: DisTubeVoiceManager;\n readonly audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected = false;\n #channel!: VoiceBasedChannel;\n #volume = 100;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"channel\");\n }\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.id = channel.guild.id;\n this.channel = channel;\n /**\n * The voice manager that instantiated this connection\n * @type {DisTubeVoiceManager}\n */\n this.voices = voiceManager;\n this.voices.add(this.id, this);\n this.audioPlayer = createAudioPlayer()\n .on(AudioPlayerStatus.Idle, oldState => {\n if (oldState.status !== AudioPlayerStatus.Idle) {\n delete this.audioResource;\n this.emit(\"finish\");\n }\n })\n .on(\"error\", error => {\n if (this.emittedError) return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.connection\n .on(VoiceConnectionStatus.Disconnected, (_, newState) => {\n if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {\n entersState(this.connection, VoiceConnectionStatus.Connecting, 5e3).catch(() => {\n this.leave();\n });\n } else if (this.connection.rejoinAttempts < 5) {\n setTimeout(() => {\n this.connection.rejoin();\n }, (this.connection.rejoinAttempts + 1) * 5e3).unref();\n } else if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.leave(new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n }\n })\n .on(VoiceConnectionStatus.Destroyed, () => {\n this.leave(new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n });\n this.connection.subscribe(this.audioPlayer);\n /**\n * Get or set the volume percentage\n * @name DisTubeVoice#volume\n * @type {number}\n */\n }\n get channel() {\n return this.#channel;\n }\n set channel(channel: VoiceBasedChannel) {\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"DisTubeVoice#channel\");\n }\n if (channel.guild.id !== this.id) throw new DisTubeError(\"VOICE_CHANGE_GUILD\");\n this.connection = this.#join(channel);\n this.audioResource?.encoder?.setBitrate(channel.bitrate);\n this.#channel = channel;\n }\n #join(channel: VoiceBasedChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: channel.guild.voiceAdapterCreator as any,\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceBasedChannel): Promise<DisTubeVoice> {\n const TIMEOUT = 30e3;\n if (channel) {\n this.channel = channel;\n }\n try {\n await entersState(this.connection, VoiceConnectionStatus.Ready, TIMEOUT);\n } catch {\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.connection.destroy();\n }\n this.voices.remove(this.id);\n throw new DisTubeError(\"VOICE_CONNECT_FAILED\", TIMEOUT / 1e3);\n }\n return this;\n }\n /**\n * Leave the voice channel of this connection\n * @param {Error} [error] Optional, an error to emit with 'error' event.\n */\n leave(error?: Error) {\n this.stop(true);\n if (!this.isDisconnected) {\n this.emit(\"disconnect\", error);\n this.isDisconnected = true;\n }\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) this.connection.destroy();\n this.voices.remove(this.id);\n }\n /**\n * Stop the playing stream\n * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state\n * even if the {@link DisTubeVoice#audioResource} has silence padding frames.\n * @private\n */\n stop(force = false) {\n this.audioPlayer.stop(force);\n }\n /**\n * Play a readable stream\n * @private\n * @param {DisTubeStream} stream Readable stream\n */\n play(stream: DisTubeStream) {\n this.emittedError = false;\n stream.stream.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (this.emittedError || error.code === \"ERR_STREAM_PREMATURE_CLOSE\") return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.audioResource = createAudioResource(stream.stream, {\n inputType: stream.type,\n inlineVolume: true,\n });\n this.volume = this.#volume;\n this.audioResource.encoder?.setBitrate(this.channel.bitrate);\n this.audioPlayer.play(this.audioResource);\n }\n set volume(volume: number) {\n if (typeof volume !== \"number\" || isNaN(volume)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"number\", volume, \"volume\");\n }\n if (volume < 0) {\n throw new DisTubeError(\"NUMBER_COMPARE\", \"Volume\", \"bigger or equal to\", 0);\n }\n this.#volume = volume;\n this.audioResource?.volume?.setVolume(Math.pow(this.#volume / 100, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this.#volume;\n }\n /**\n * Playback duration of the audio resource in seconds\n * @type {number}\n */\n get playbackDuration() {\n return (this.audioResource?.playbackDuration ?? 0) / 1000;\n }\n pause() {\n this.audioPlayer.pause();\n }\n unpause() {\n this.audioPlayer.unpause();\n }\n /**\n * Whether the bot is self-deafened\n * @type {boolean}\n */\n get selfDeaf(): boolean {\n return this.connection.joinConfig.selfDeaf;\n }\n /**\n * Whether the bot is self-muted\n * @type {boolean}\n */\n get selfMute(): boolean {\n return this.connection.joinConfig.selfMute;\n }\n /**\n * Self-deafens/undeafens the bot.\n * @param {boolean} selfDeaf Whether or not the bot should be self-deafened\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfDeaf(selfDeaf: boolean): boolean {\n if (typeof selfDeaf !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfDeaf, \"selfDeaf\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfDeaf,\n });\n }\n /**\n * Self-mutes/unmutes the bot.\n * @param {boolean} selfMute Whether or not the bot should be self-muted\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfMute(selfMute: boolean): boolean {\n if (typeof selfMute !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfMute, \"selfMute\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfMute,\n });\n }\n /**\n * The voice state of this connection\n * @type {Discord.VoiceState?}\n */\n get voiceState(): VoiceState | undefined {\n return this.channel?.guild?.me?.voice;\n }\n}\n"]}
@@ -1,41 +1,10 @@
1
1
  import { DisTubeVoice } from ".";
2
- import { BaseManager } from "../manager";
2
+ import { GuildIdManager } from "../manager";
3
3
  import type { GuildIdResolvable } from "../..";
4
4
  import type { VoiceBasedChannel } from "discord.js";
5
- /**
6
- * Manages voice connections for {@link DisTube}
7
- * @extends BaseManager
8
- */
9
- export declare class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {
10
- /**
11
- * Get a {@link DisTubeVoice}.
12
- * @method get
13
- * @memberof DisTubeVoiceManager#
14
- * @param {GuildIdResolvable} queue The queue resolvable to resolve
15
- * @returns {DisTubeVoice?}
16
- */
17
- /**
18
- * Collection of {@link DisTubeVoice}.
19
- * @name DisTubeVoiceManager#collection
20
- * @type {Discord.Collection<string, DisTubeVoice>}
21
- */
22
- /**
23
- * Create a {@link DisTubeVoice}
24
- * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
25
- * @returns {DisTubeVoice}
26
- * @private
27
- */
5
+ export declare class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {
28
6
  create(channel: VoiceBasedChannel): DisTubeVoice;
29
- /**
30
- * Join a voice channel
31
- * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
32
- * @returns {Promise<DisTubeVoice>}
33
- */
34
7
  join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
35
- /**
36
- * Leave the connected voice channel in a guild
37
- * @param {GuildIdResolvable} guild Queue Resolvable
38
- */
39
8
  leave(guild: GuildIdResolvable): void;
40
9
  }
41
10
  //# sourceMappingURL=DisTubeVoiceManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DisTubeVoiceManager.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,WAAW,CAAC,YAAY,CAAC;IAChE;;;;;;OAMG;IACH;;;;OAIG;IACH;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY;IAOhD;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAKvD;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,iBAAiB;CAW/B"}
1
+ {"version":3,"file":"DisTubeVoiceManager.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMpD,qBAAa,mBAAoB,SAAQ,cAAc,CAAC,YAAY,CAAC;IAmBnE,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY;IAYhD,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IASvD,KAAK,CAAC,KAAK,EAAE,iBAAiB;CAW/B"}