distube 3.1.1 → 3.2.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/DisTube.d.ts +38 -31
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +36 -25
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +1 -1
- package/dist/constant.js +1 -1
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeHandler.js +8 -13
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/manager/BaseManager.d.ts +4 -4
- package/dist/core/manager/BaseManager.js.map +1 -1
- package/dist/core/manager/QueueManager.js +1 -2
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/voice/DJSAdapter.js +4 -7
- package/dist/core/voice/DJSAdapter.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +4 -8
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.d.ts +4 -4
- package/dist/core/voice/DisTubeVoiceManager.js +2 -2
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/https.js +1 -1
- package/dist/plugin/https.js.map +1 -1
- package/dist/plugin/youtube-dl.js +1 -2
- package/dist/plugin/youtube-dl.js.map +1 -1
- package/dist/struct/Playlist.js +3 -6
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Queue.js +3 -6
- package/dist/struct/Queue.js.map +1 -1
- package/dist/struct/SearchResult.js +2 -3
- package/dist/struct/SearchResult.js.map +1 -1
- package/dist/struct/Song.js +8 -11
- package/dist/struct/Song.js.map +1 -1
- package/dist/struct/TaskQueue.js +1 -2
- package/dist/struct/TaskQueue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.js +9 -14
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -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;;;IAkLA,CAAC;IAjLC;;;;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,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvC,OAAO,GAAG,IAAI,KAAK,CAAC;SACrB;gBAAS;YACR,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IAgGD;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CA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E;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,mEA4Ca,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,CAAA,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,OAAK,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,CAAA,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 song.streamURL = await plugin.getStreamURL(url);\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,wBAAgC;AAChC,6BAAwD;AAIxD;;;GAGG;AACH,MAAa,YAAa,SAAQ,cAAkB;IAApD;;;IAkLA,CAAC;IAjLC;;;;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,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvC,OAAO,GAAG,IAAI,KAAK,CAAC;SACrB;gBAAS;YACR,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IAgGD;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAY;QACzB,IAAI,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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,mEA4Ca,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 song.streamURL = await plugin.getStreamURL(url);\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"]}
|
|
@@ -9,21 +9,18 @@ function trackClient(client) {
|
|
|
9
9
|
return;
|
|
10
10
|
trackedClients.add(client);
|
|
11
11
|
client.ws.on(discord_js_1.Constants.WSEvents.VOICE_SERVER_UPDATE, (payload) => {
|
|
12
|
-
|
|
13
|
-
(_a = adapters.get(payload.guild_id)) === null || _a === void 0 ? void 0 : _a.onVoiceServerUpdate(payload);
|
|
12
|
+
adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
|
14
13
|
});
|
|
15
14
|
client.ws.on(discord_js_1.Constants.WSEvents.VOICE_STATE_UPDATE, (payload) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(_b = adapters.get(payload.guild_id)) === null || _b === void 0 ? void 0 : _b.onVoiceStateUpdate(payload);
|
|
15
|
+
if (payload.guild_id && payload.session_id && payload.user_id === client.user?.id) {
|
|
16
|
+
adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);
|
|
19
17
|
}
|
|
20
18
|
});
|
|
21
19
|
client.on(discord_js_1.Constants.Events.SHARD_DISCONNECT, (_, shardID) => {
|
|
22
|
-
var _a;
|
|
23
20
|
const guilds = trackedShards.get(shardID);
|
|
24
21
|
if (guilds) {
|
|
25
22
|
for (const guildID of guilds.values()) {
|
|
26
|
-
|
|
23
|
+
adapters.get(guildID)?.destroy();
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
trackedShards.delete(shardID);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DJSAdapter.js","sourceRoot":"","sources":["../../../src/core/voice/DJSAdapter.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAKvC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkD,CAAC;AAC3E,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;AAEzC,SAAS,WAAW,CAAC,MAAc;IACjC,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO;IACvC,cAAc,CAAC,G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AE,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAlBD,wDAkBC","sourcesContent":["import { Constants } from \"discord.js\";\nimport type { Client, Snowflake, VoiceChannel } from \"discord.js\";\nimport type { DiscordGatewayAdapterCreator, DiscordGatewayAdapterLibraryMethods } from \"@discordjs/voice\";\nimport type { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from \"discord-api-types/v9\";\n\nconst adapters = new Map<Snowflake, DiscordGatewayAdapterLibraryMethods>();\nconst trackedClients = new Set<Client>();\n\nfunction trackClient(client: Client) {\n if (trackedClients.has(client)) return;\n trackedClients.add(client);\n client.ws.on(Constants.WSEvents.VOICE_SERVER_UPDATE, (payload: GatewayVoiceServerUpdateDispatchData) => {\n adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);\n });\n client.ws.on(Constants.WSEvents.VOICE_STATE_UPDATE, (payload: GatewayVoiceStateUpdateDispatchData) => {\n if (payload.guild_id && payload.session_id && payload.user_id === client.user?.id) {\n adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);\n }\n });\n client.on(Constants.Events.SHARD_DISCONNECT, (_, shardID) => {\n const guilds = trackedShards.get(shardID);\n if (guilds) {\n for (const guildID of guilds.values()) {\n adapters.get(guildID)?.destroy();\n }\n }\n trackedShards.delete(shardID);\n });\n}\n\nconst trackedShards = new Map<number, Set<Snowflake>>();\n\nfunction trackGuild(guild: any) {\n let guilds = trackedShards.get(guild.shardID);\n if (!guilds) {\n guilds = new Set();\n trackedShards.set(guild.shardID, guilds);\n }\n guilds.add(guild.id);\n}\n\nexport function createDiscordJSAdapter(channel: VoiceChannel): DiscordGatewayAdapterCreator {\n return methods => {\n adapters.set(channel.guild.id, methods);\n trackClient(channel.client);\n trackGuild(channel.guild);\n return {\n sendPayload(data) {\n if (channel.guild.shard.status === Constants.Status.READY) {\n channel.guild.shard.send(data);\n return true;\n }\n return false;\n },\n destroy() {\n return adapters.delete(channel.guild.id);\n },\n };\n };\n}\n"]}
|
|
@@ -103,7 +103,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
103
103
|
* @returns {Promise<DisTubeVoice>}
|
|
104
104
|
*/
|
|
105
105
|
async join(channel) {
|
|
106
|
-
var _a;
|
|
107
106
|
const TIMEOUT = 30e3;
|
|
108
107
|
if (channel) {
|
|
109
108
|
this.channel = channel;
|
|
@@ -116,7 +115,7 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
116
115
|
this.connection.destroy();
|
|
117
116
|
}
|
|
118
117
|
this.voices.delete(this.id);
|
|
119
|
-
if (
|
|
118
|
+
if (this.voiceState?.connection)
|
|
120
119
|
throw new __1.DisTubeError("VOICE_DEPRECATED_CONNECTION");
|
|
121
120
|
throw new __1.DisTubeError("VOICE_CONNECT_FAILED", TIMEOUT / 1e3);
|
|
122
121
|
}
|
|
@@ -167,7 +166,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
167
166
|
this.audioPlayer.play(this.audioResource);
|
|
168
167
|
}
|
|
169
168
|
set volume(volume) {
|
|
170
|
-
var _a, _b;
|
|
171
169
|
if (typeof volume !== "number" || isNaN(volume)) {
|
|
172
170
|
throw new __1.DisTubeError("INVALID_TYPE", "number", volume, "volume");
|
|
173
171
|
}
|
|
@@ -175,7 +173,7 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
175
173
|
throw new __1.DisTubeError("NUMBER_COMPARE", "Volume", "bigger or equal to", 0);
|
|
176
174
|
}
|
|
177
175
|
__classPrivateFieldSet(this, _DisTubeVoice_volume, volume, "f");
|
|
178
|
-
|
|
176
|
+
this.audioResource?.volume?.setVolume(Math.pow(__classPrivateFieldGet(this, _DisTubeVoice_volume, "f") / 100, 0.5 / Math.log10(2)));
|
|
179
177
|
}
|
|
180
178
|
get volume() {
|
|
181
179
|
return __classPrivateFieldGet(this, _DisTubeVoice_volume, "f");
|
|
@@ -185,8 +183,7 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
185
183
|
* @type {number}
|
|
186
184
|
*/
|
|
187
185
|
get playbackDuration() {
|
|
188
|
-
|
|
189
|
-
return ((_b = (_a = this.audioResource) === null || _a === void 0 ? void 0 : _a.playbackDuration) !== null && _b !== void 0 ? _b : 0) / 1000;
|
|
186
|
+
return (this.audioResource?.playbackDuration ?? 0) / 1000;
|
|
190
187
|
}
|
|
191
188
|
pause() {
|
|
192
189
|
this.audioPlayer.pause();
|
|
@@ -241,8 +238,7 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
241
238
|
* @type {Discord.VoiceState?}
|
|
242
239
|
*/
|
|
243
240
|
get voiceState() {
|
|
244
|
-
|
|
245
|
-
return (_c = (_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.guild) === null || _b === void 0 ? void 0 : _b.me) === null || _c === void 0 ? void 0 : _c.voice;
|
|
241
|
+
return this.channel?.guild?.me?.voice;
|
|
246
242
|
}
|
|
247
243
|
}
|
|
248
244
|
exports.DisTubeVoice = DisTubeVoice;
|
|
@@ -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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;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IACD;;;OAGG;IACH,IAAI,UAAU;;QACZ,OAAO,MAAA,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,KAAK,0CAAE,EAAE,0CAAE,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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AAW,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;IACD;;;;OAIG;IACH,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;IACD;;;OAGG;IACH,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,6 +1,6 @@
|
|
|
1
1
|
import { DisTubeVoice } from ".";
|
|
2
2
|
import { BaseManager } from "../manager";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GuildIdResolvable } from "../..";
|
|
4
4
|
import type { VoiceBasedChannel } from "discord.js";
|
|
5
5
|
/**
|
|
6
6
|
* Manages voice connections for {@link DisTube}
|
|
@@ -11,7 +11,7 @@ export declare class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {
|
|
|
11
11
|
* Get a {@link DisTubeVoice}.
|
|
12
12
|
* @method get
|
|
13
13
|
* @memberof DisTubeVoiceManager#
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {GuildIdResolvable} queue The queue resolvable to resolve
|
|
15
15
|
* @returns {DisTubeVoice?}
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
@@ -34,8 +34,8 @@ export declare class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {
|
|
|
34
34
|
join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
|
|
35
35
|
/**
|
|
36
36
|
* Leave the connected voice channel in a guild
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {GuildIdResolvable} guild Queue Resolvable
|
|
38
38
|
*/
|
|
39
|
-
leave(guild:
|
|
39
|
+
leave(guild: GuildIdResolvable): void;
|
|
40
40
|
}
|
|
41
41
|
//# sourceMappingURL=DisTubeVoiceManager.d.ts.map
|
|
@@ -14,7 +14,7 @@ class DisTubeVoiceManager extends manager_1.BaseManager {
|
|
|
14
14
|
* Get a {@link DisTubeVoice}.
|
|
15
15
|
* @method get
|
|
16
16
|
* @memberof DisTubeVoiceManager#
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {GuildIdResolvable} queue The queue resolvable to resolve
|
|
18
18
|
* @returns {DisTubeVoice?}
|
|
19
19
|
*/
|
|
20
20
|
/**
|
|
@@ -48,7 +48,7 @@ class DisTubeVoiceManager extends manager_1.BaseManager {
|
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Leave the connected voice channel in a guild
|
|
51
|
-
* @param {
|
|
51
|
+
* @param {GuildIdResolvable} guild Queue Resolvable
|
|
52
52
|
*/
|
|
53
53
|
leave(guild) {
|
|
54
54
|
const voice = this.get(guild);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoiceManager.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,6BAAuC;AACvC,wCAAyC;AACzC,4CAA6E;AAI7E;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,qBAAyB;IAChE;;;;;;OAMG;IACH;;;;OAIG;IACH;;;;;OAKG;IACH,MAAM,CAAC,OAA0B;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC;SACjB;QACD,OAAO,IAAI,eAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAC,OAA0B;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD;;;OAGG;IACH,KAAK,CAAC,KAAwB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;aAAM;YACL,MAAM,UAAU,GAAG,IAAA,0BAAkB,EAAC,IAAA,kBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7D,IAAI,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,6BAAqB,CAAC,SAAS,EAAE;gBAC7E,UAAU,CAAC,OAAO,EAAE,CAAC;aACtB;SACF;IACH,CAAC;CACF;AAnDD,kDAmDC","sourcesContent":["import { DisTubeVoice } from \".\";\nimport { resolveGuildID } from \"../..\";\nimport { BaseManager } from \"../manager\";\nimport { VoiceConnectionStatus, getVoiceConnection } from \"@discordjs/voice\";\nimport type {
|
|
1
|
+
{"version":3,"file":"DisTubeVoiceManager.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,6BAAuC;AACvC,wCAAyC;AACzC,4CAA6E;AAI7E;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,qBAAyB;IAChE;;;;;;OAMG;IACH;;;;OAIG;IACH;;;;;OAKG;IACH,MAAM,CAAC,OAA0B;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC;SACjB;QACD,OAAO,IAAI,eAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAC,OAA0B;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD;;;OAGG;IACH,KAAK,CAAC,KAAwB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;aAAM;YACL,MAAM,UAAU,GAAG,IAAA,0BAAkB,EAAC,IAAA,kBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7D,IAAI,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,6BAAqB,CAAC,SAAS,EAAE;gBAC7E,UAAU,CAAC,OAAO,EAAE,CAAC;aACtB;SACF;IACH,CAAC;CACF;AAnDD,kDAmDC","sourcesContent":["import { DisTubeVoice } from \".\";\nimport { resolveGuildID } from \"../..\";\nimport { BaseManager } from \"../manager\";\nimport { VoiceConnectionStatus, getVoiceConnection } from \"@discordjs/voice\";\nimport type { GuildIdResolvable } from \"../..\";\nimport type { VoiceBasedChannel } from \"discord.js\";\n\n/**\n * Manages voice connections for {@link DisTube}\n * @extends BaseManager\n */\nexport class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {\n /**\n * Get a {@link DisTubeVoice}.\n * @method get\n * @memberof DisTubeVoiceManager#\n * @param {GuildIdResolvable} queue The queue resolvable to resolve\n * @returns {DisTubeVoice?}\n */\n /**\n * Collection of {@link DisTubeVoice}.\n * @name DisTubeVoiceManager#collection\n * @type {Discord.Collection<string, DisTubeVoice>}\n */\n /**\n * Create a {@link DisTubeVoice}\n * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join\n * @returns {DisTubeVoice}\n * @private\n */\n create(channel: VoiceBasedChannel): DisTubeVoice {\n const existing = this.get(channel.guild.id);\n if (existing) {\n return existing;\n }\n return new DisTubeVoice(this, channel);\n }\n /**\n * Join a voice channel\n * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join\n * @returns {Promise<DisTubeVoice>}\n */\n join(channel: VoiceBasedChannel): Promise<DisTubeVoice> {\n const existing = this.get(channel.guild.id);\n if (existing) return existing.join(channel);\n return this.create(channel).join();\n }\n /**\n * Leave the connected voice channel in a guild\n * @param {GuildIdResolvable} guild Queue Resolvable\n */\n leave(guild: GuildIdResolvable) {\n const voice = this.get(guild);\n if (voice) {\n voice.leave();\n } else {\n const connection = getVoiceConnection(resolveGuildID(guild));\n if (connection && connection.state.status !== VoiceConnectionStatus.Destroyed) {\n connection.destroy();\n }\n }\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.default = exports.DisTube = void 0;
|
|
13
|
+
exports.version = exports.default = exports.DisTube = void 0;
|
|
14
14
|
__exportStar(require("./type"), exports);
|
|
15
15
|
__exportStar(require("./constant"), exports);
|
|
16
16
|
__exportStar(require("./struct"), exports);
|
|
@@ -20,4 +20,5 @@ __exportStar(require("./plugin"), exports);
|
|
|
20
20
|
var DisTube_1 = require("./DisTube");
|
|
21
21
|
Object.defineProperty(exports, "DisTube", { enumerable: true, get: function () { return DisTube_1.DisTube; } });
|
|
22
22
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return DisTube_1.DisTube; } });
|
|
23
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return DisTube_1.version; } });
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB;AACvB,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB;AACvB,2CAAyB;AACzB,qCAAiE;AAAxD,kGAAA,OAAO,OAAA;AAAE,kGAAA,OAAO,OAAW;AAAE,kGAAA,OAAO,OAAA","sourcesContent":["export * from \"./type\";\nexport * from \"./constant\";\nexport * from \"./struct\";\nexport * from \"./util\";\nexport * from \"./core\";\nexport * from \"./plugin\";\nexport { DisTube, DisTube as default, version } from \"./DisTube\";\n"]}
|
package/dist/plugin/https.js
CHANGED
|
@@ -21,7 +21,7 @@ const validateAudioURL = async (httpModule, protocol, url) => {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
const headers = await (0, exports.getResponseHeaders)(httpModule, url), type = headers["content-type"];
|
|
24
|
-
if (type
|
|
24
|
+
if (type?.startsWith("audio")) {
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
27
|
return false;
|
package/dist/plugin/https.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"https.js","sourceRoot":"","sources":["../../src/plugin/https.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,6BAA0B;AAC1B,0BAA2C;AAIpC,MAAM,kBAAkB,GAAG,KAAK,EACrC,UAAsC,EACtC,GAAW,EACwB,EAAE,CACrC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,UAAU;SACP,GAAG,CAAC,GAAG,CAAC;SACR,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC;SACD,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAXQ,QAAA,kBAAkB,sBAW1B;AAEE,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAsC,EAAE,QAAgB,EAAE,GAAW,EAAE,EAAE;IAC9G,IAAI,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE;QACpD,OAAO,KAAK,CAAC;KACd;IACD,MAAM,OAAO,GAAG,MAAM,IAAA,0BAAkB,EAAC,UAAU,EAAE,GAAG,CAAC,EACvD,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACj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AAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,GAAG;QAChF,GAAG;KACJ,EACD,OAAO,CACR,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,eAAe,mBAa1B;AAEF,MAAa,WAAY,SAAQ,mBAAe;IAC9C,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,OAAO,IAAA,wBAAgB,EAAC,eAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,UAAoD,EAAE;QAC/E,OAAO,IAAA,uBAAe,EAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AARD,kCAQC","sourcesContent":["import https from \"https\";\nimport { URL } from \"url\";\nimport { ExtractorPlugin, Song } from \"..\";\nimport type http from \"http\";\nimport type { GuildMember } from \"discord.js\";\n\nexport const getResponseHeaders = async (\n httpModule: typeof http | typeof https,\n url: string,\n): Promise<http.IncomingHttpHeaders> =>\n new Promise((resolve, reject) => {\n httpModule\n .get(url)\n .on(\"response\", res => {\n resolve(res.headers);\n })\n .on(\"error\", reject);\n });\n\nexport const validateAudioURL = async (httpModule: typeof http | typeof https, protocol: string, url: string) => {\n if (new URL(url).protocol.toLowerCase() !== protocol) {\n return false;\n }\n const headers = await getResponseHeaders(httpModule, url),\n type = headers[\"content-type\"];\n if (type?.startsWith(\"audio\")) {\n return true;\n }\n return false;\n};\n\nexport const resolveHttpSong = async (\n url: string,\n options: { source: \"http\" | \"https\"; member?: GuildMember; metadata?: any },\n // eslint-disable-next-line @typescript-eslint/require-await\n) => {\n url = url.replace(/\\/+$/, \"\");\n return new Song(\n {\n name: url.substring(url.lastIndexOf(\"/\") + 1).replace(/((\\?|#).*)?$/, \"\") || url,\n url,\n },\n options,\n );\n};\n\nexport class HTTPSPlugin extends ExtractorPlugin {\n async validate(url: string) {\n return validateAudioURL(https, \"https:\", url);\n }\n\n async resolve(url: string, options: { member?: GuildMember; metadata?: any } = {}) {\n return resolveHttpSong(url, { ...options, source: \"https\" });\n }\n}\n"]}
|
|
@@ -39,7 +39,6 @@ class YouTubeDLPlugin extends __1.ExtractorPlugin {
|
|
|
39
39
|
return true;
|
|
40
40
|
}
|
|
41
41
|
async resolve(url, { member, metadata }) {
|
|
42
|
-
var _a;
|
|
43
42
|
const info = await (0, youtube_dl_1.default)(url, {
|
|
44
43
|
dumpSingleJson: true,
|
|
45
44
|
noWarnings: true,
|
|
@@ -51,7 +50,7 @@ class YouTubeDLPlugin extends __1.ExtractorPlugin {
|
|
|
51
50
|
if (Array.isArray(info.entries) && info.entries.length > 0) {
|
|
52
51
|
info.source = info.extractor.match(/\w+/)[0];
|
|
53
52
|
info.songs = info.entries.map((i) => new __1.Song(i, { member, source: i.extractor, metadata }));
|
|
54
|
-
return new __1.Playlist(info, { member, metadata, properties: { source:
|
|
53
|
+
return new __1.Playlist(info, { member, metadata, properties: { source: info.songs[0]?.source } });
|
|
55
54
|
}
|
|
56
55
|
return new __1.Song(info, { member, source: info.extractor, metadata });
|
|
57
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"youtube-dl.js","sourceRoot":"","sources":["../../src/plugin/youtube-dl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,kEAA8D;AAC9D,0BAAqD;AAKrD,MAAa,eAAgB,SAAQ,mBAAe;IAClD,YAAY,eAAe,GAAG,IAAI;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,eAAe,EAAE;YACnB,+BAA+B;YAC/B,IAAA,qBAAQ,GAAE;iBACP,IAAI,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mCAAmC,OAAO,GAAG,CAAC,CAAC;iBAClF,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;iBACpB,KAAK,C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["import youtubeDlExec, { download } from \"@distube/youtube-dl\";\nimport { ExtractorPlugin, Playlist, Song } from \"..\";\nimport type { OtherSongInfo } from \"..\";\nimport type { GuildMember } from \"discord.js\";\nimport type { YtResponse } from \"@distube/youtube-dl\";\n\nexport class YouTubeDLPlugin extends ExtractorPlugin {\n constructor(updateYouTubeDL = true) {\n super();\n if (updateYouTubeDL) {\n /* eslint-disable no-console */\n download()\n .then((version: any) => console.log(`[DisTube] Updated youtube-dl to ${version}!`))\n .catch(console.error)\n .catch(() => console.warn(\"[DisTube] Unable to update youtube-dl, using default version.\"));\n /* eslint-enable no-console */\n }\n }\n // eslint-disable-next-line @typescript-eslint/require-await\n async validate() {\n return true;\n }\n\n async resolve(url: string, { member, metadata }: { member?: GuildMember; metadata?: any }) {\n const info: any = await youtubeDlExec(url, {\n dumpSingleJson: true,\n noWarnings: true,\n noCallHome: true,\n preferFreeFormats: true,\n }).catch(e => {\n throw new Error(`[youtube-dl] ${e.stderr || e}`);\n });\n if (Array.isArray(info.entries) && info.entries.length > 0) {\n info.source = info.extractor.match(/\\w+/)[0];\n info.songs = info.entries.map(\n (i: OtherSongInfo & YtResponse) => new Song(i, { member, source: i.extractor, metadata }),\n );\n return new Playlist(info, { member, metadata, properties: { source: info.songs[0]?.source } });\n }\n return new Song(info, { member, source: info.extractor, metadata });\n }\n async getStreamURL(url: string) {\n const info = await youtubeDlExec(url, {\n dumpSingleJson: true,\n noWarnings: true,\n noCallHome: true,\n preferFreeFormats: true,\n }).catch(e => {\n throw new Error(`[youtube-dl] ${e.stderr || e}`);\n });\n return info.url;\n }\n}\n"]}
|
package/dist/struct/Playlist.js
CHANGED
|
@@ -10,7 +10,6 @@ const __1 = require("..");
|
|
|
10
10
|
*/
|
|
11
11
|
class Playlist {
|
|
12
12
|
constructor(playlist, options = {}, props = {}, meta) {
|
|
13
|
-
var _a;
|
|
14
13
|
if ((0, __1.isMemberInstance)(options)) {
|
|
15
14
|
process.emitWarning("Passing GuildMember for DisTube#Playlist() is deprecated, read the docs for more.", "DeprecationWarning");
|
|
16
15
|
return new Playlist(playlist, { member: options, properties: props, metadata: meta });
|
|
@@ -57,7 +56,7 @@ class Playlist {
|
|
|
57
56
|
* Playlist thumbnail.
|
|
58
57
|
* @type {?string}
|
|
59
58
|
*/
|
|
60
|
-
this.thumbnail =
|
|
59
|
+
this.thumbnail = info.thumbnail?.url || info.thumbnail || this.songs[0].thumbnail;
|
|
61
60
|
for (const [key, value] of Object.entries(properties)) {
|
|
62
61
|
this[key] = value;
|
|
63
62
|
}
|
|
@@ -73,8 +72,7 @@ class Playlist {
|
|
|
73
72
|
* @type {number}
|
|
74
73
|
*/
|
|
75
74
|
get duration() {
|
|
76
|
-
|
|
77
|
-
return ((_a = this.songs) === null || _a === void 0 ? void 0 : _a.reduce((prev, next) => prev + (next.duration || 0), 0)) || 0;
|
|
75
|
+
return this.songs?.reduce((prev, next) => prev + (next.duration || 0), 0) || 0;
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
80
78
|
* Formatted duration string `hh:mm:ss`.
|
|
@@ -89,7 +87,6 @@ class Playlist {
|
|
|
89
87
|
* @returns {Playlist}
|
|
90
88
|
*/
|
|
91
89
|
_patchMember(member) {
|
|
92
|
-
var _a;
|
|
93
90
|
if (member) {
|
|
94
91
|
/**
|
|
95
92
|
* User requested.
|
|
@@ -100,7 +97,7 @@ class Playlist {
|
|
|
100
97
|
* User requested.
|
|
101
98
|
* @type {?Discord.User}
|
|
102
99
|
*/
|
|
103
|
-
this.user =
|
|
100
|
+
this.user = this.member?.user;
|
|
104
101
|
}
|
|
105
102
|
this.songs.map(s => s.constructor.name === "Song" && s._patchPlaylist(this, this.member));
|
|
106
103
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Playlist.js","sourceRoot":"","sources":["../../src/struct/Playlist.ts"],"names":[],"mappings":";;;AAAA,0BAAoE;AAKpE,2CAA2C;AAE3C;;;;GAIG;AACH,MAAa,QAAQ;IAkCnB,YAC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I,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACjF,CAAC;IAED;;;OAGG;IACH,IAAI,iBAAiB;QACnB,OAAO,IAAA,kBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,MAAoB;QAC/B,IAAI,MAAM,EAAE;YACV;;;eAGG;YACH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB;;;eAGG;YACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;SAC/B;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1F,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAc,QAAW;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAwB,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjF,OAAO,IAA8B,CAAC;IACxC,CAAC;CACF;AA7JD,4BA6JC","sourcesContent":["import { DisTubeError, formatDuration, isMemberInstance } from \"..\";\nimport type ytpl from \"@distube/ytpl\";\nimport type { PlaylistInfo, Song } from \"..\";\nimport type { GuildMember, User } from \"discord.js\";\n\n// TODO: Remove ! on the next major version\n\n/**\n * Class representing a playlist.\n * @prop {string} source Playlist source\n * @template T - The type for the metadata (if any) of the playlist\n */\nexport class Playlist<T = unknown> implements PlaylistInfo {\n source!: string;\n songs!: Song[];\n name!: string;\n metadata!: T;\n member?: GuildMember;\n user?: User;\n url?: string;\n thumbnail?: string;\n [x: string]: any;\n constructor(playlist: Song[] | ytpl.result | PlaylistInfo);\n /** @deprecated Passing GuildMember for DisTube#Playlist() is deprecated. */\n constructor(\n playlist: Song[] | ytpl.result | PlaylistInfo,\n member?: GuildMember,\n properties?: Record<string, any>,\n metadata?: T,\n );\n /**\n * Create a playlist\n * @param {Song[]|PlaylistInfo} playlist Playlist\n * @param {Object} [options] Optional options\n * @param {Discord.GuildMember} [options.member] Requested user\n * @param {Object} [options.properties] Custom properties\n * @param {T} [options.metadata] Playlist metadata\n */\n constructor(\n playlist: Song[] | ytpl.result | PlaylistInfo,\n options?: {\n member?: GuildMember;\n properties?: Record<string, any>;\n metadata?: T;\n },\n );\n constructor(\n playlist: Song[] | ytpl.result | PlaylistInfo,\n options:\n | GuildMember\n | {\n member?: GuildMember;\n properties?: Record<string, any>;\n metadata?: T;\n } = {},\n props: Record<string, any> = {},\n meta?: T,\n ) {\n if (isMemberInstance(options)) {\n process.emitWarning(\n \"Passing GuildMember for DisTube#Playlist() is deprecated, read the docs for more.\",\n \"DeprecationWarning\",\n );\n return new Playlist(playlist, { member: options, properties: props, metadata: meta });\n }\n\n const { member, properties, metadata } = Object.assign({ properties: {} }, options);\n\n if (typeof playlist !== \"object\") {\n throw new DisTubeError(\"INVALID_TYPE\", [\"Array<Song>\", \"object\"], playlist, \"playlist\");\n }\n if (typeof properties !== \"object\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"object\", properties, \"properties\");\n }\n // FIXME\n const info = playlist as any;\n /**\n * The source of the playlist\n * @type {string}\n */\n this.source = (info.source || properties.source || \"youtube\").toLowerCase();\n /**\n * Playlist songs.\n * @type {Array<Song>}\n */\n this.songs = Array.isArray(info) ? info : info.items || info.songs;\n if (!Array.isArray(this.songs) || !this.songs.length) {\n throw new DisTubeError(\"EMPTY_PLAYLIST\");\n }\n this._patchMember(member || info.member);\n /**\n * Playlist name.\n * @type {string}\n */\n this.name =\n info.name ||\n info.title ||\n (this.songs[0].name\n ? `${this.songs[0].name} and ${this.songs.length - 1} more songs.`\n : `${this.songs.length} songs playlist`);\n /**\n * Playlist URL.\n * @type {string}\n */\n this.url = info.url || info.webpage_url;\n /**\n * Playlist thumbnail.\n * @type {?string}\n */\n this.thumbnail = info.thumbnail?.url || info.thumbnail || this.songs[0].thumbnail;\n for (const [key, value] of Object.entries(properties)) {\n this[key] = value;\n }\n /**\n * Optional metadata that can be used to identify the playlist.\n * @type {T}\n */\n this.metadata = metadata as T;\n this._patchMetadata(metadata);\n }\n\n /**\n * Playlist duration in second.\n * @type {number}\n */\n get duration() {\n return this.songs?.reduce((prev, next) => prev + (next.duration || 0), 0) || 0;\n }\n\n /**\n * Formatted duration string `hh:mm:ss`.\n * @type {string}\n */\n get formattedDuration() {\n return formatDuration(this.duration);\n }\n\n /**\n * @param {?Discord.GuildMember} [member] Requested user\n * @private\n * @returns {Playlist}\n */\n _patchMember(member?: GuildMember) {\n if (member) {\n /**\n * User requested.\n * @type {?Discord.GuildMember}\n */\n this.member = member;\n /**\n * User requested.\n * @type {?Discord.User}\n */\n this.user = this.member?.user;\n }\n this.songs.map(s => s.constructor.name === \"Song\" && s._patchPlaylist(this, this.member));\n return this;\n }\n\n /**\n * @param {*} metadata Metadata\n * @private\n * @returns {Playlist}\n */\n _patchMetadata<S = unknown>(metadata: S) {\n this.metadata = metadata as unknown as T;\n this.songs.map(s => s.constructor.name === \"Song\" && s._patchMetadata(metadata));\n return this as unknown as Playlist<S>;\n }\n}\n"]}
|
package/dist/struct/Queue.js
CHANGED
|
@@ -16,13 +16,12 @@ class Queue extends core_1.DisTubeBase {
|
|
|
16
16
|
* @param {Discord.BaseGuildTextChannel?} textChannel Default text channel
|
|
17
17
|
*/
|
|
18
18
|
constructor(distube, voice, song, textChannel) {
|
|
19
|
-
var _a;
|
|
20
19
|
super(distube);
|
|
21
20
|
/**
|
|
22
21
|
* The client user as a `GuildMember` of this queue's guild
|
|
23
22
|
* @type {Discord.GuildMember}
|
|
24
23
|
*/
|
|
25
|
-
this.clientMember =
|
|
24
|
+
this.clientMember = voice.channel.guild?.me;
|
|
26
25
|
/**
|
|
27
26
|
* Voice connection of this queue.
|
|
28
27
|
* @type {DisTubeVoice}
|
|
@@ -261,12 +260,11 @@ class Queue extends core_1.DisTubeBase {
|
|
|
261
260
|
* @throws {Error}
|
|
262
261
|
*/
|
|
263
262
|
async previous() {
|
|
264
|
-
var _a;
|
|
265
263
|
await this.taskQueue.queuing();
|
|
266
264
|
try {
|
|
267
265
|
if (!this.options.savePreviousSongs)
|
|
268
266
|
throw new __1.DisTubeError("DISABLED_OPTION", "savePreviousSongs");
|
|
269
|
-
if (
|
|
267
|
+
if (this.previousSongs?.length === 0 && this.repeatMode !== __1.RepeatMode.QUEUE) {
|
|
270
268
|
throw new __1.DisTubeError("NO_PREVIOUS");
|
|
271
269
|
}
|
|
272
270
|
const song = this.repeatMode === 2 ? this.songs[this.songs.length - 1] : this.previousSongs[this.previousSongs.length - 1];
|
|
@@ -421,8 +419,7 @@ class Queue extends core_1.DisTubeBase {
|
|
|
421
419
|
* @throws {Error}
|
|
422
420
|
*/
|
|
423
421
|
async addRelatedSong() {
|
|
424
|
-
|
|
425
|
-
if (!((_a = this.songs) === null || _a === void 0 ? void 0 : _a[0]))
|
|
422
|
+
if (!this.songs?.[0])
|
|
426
423
|
throw new __1.DisTubeError("NO_PLAYING");
|
|
427
424
|
const related = this.songs[0].related.find(v => !this.previousSongs.map(s => s.id).includes(v.id));
|
|
428
425
|
if (!related || !(related instanceof __1.Song))
|