distube 3.0.0 → 3.0.4
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/README.md +3 -4
- package/dist/DisTube.js +2 -2
- package/dist/DisTube.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +12 -1
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +41 -15
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/manager/QueueManager.js +4 -2
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts +3 -1
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +14 -4
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/struct/DisTubeError.d.ts +2 -0
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +5 -8
- package/dist/struct/DisTubeError.js.map +1 -1
- package/dist/struct/Queue.js +2 -1
- package/dist/struct/Queue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/tsconfig.eslint.json +0 -5
|
@@ -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;AAWlD,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;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpF;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY,CAAC,kBAAkB,CAAC;IAChE,E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CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,OAAO,CAAS;gBACZ,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY;IAuDnF,IAAI,OAAO,IAGU,YAAY,GAAG,YAAY,CAD/C;IACD,IAAI,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,EAK/C;IACD,OAAO,CAAC,KAAK;IAOb;;;;;OAKG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAiBxE;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK;IAanB;;;;;OAKG;IACH,IAAI,CAAC,KAAK,UAAQ;IAGlB;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,aAAa;IAe1B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EASxB;IACD,IAAI,MAAM,IAVS,MAAM,CAYxB;IACD;;;OAGG;IACH,IAAI,gBAAgB,WAEnB;IACD,KAAK;IAGL,OAAO;IAGP;;;OAGG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD;;;OAGG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IASvC;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IASvC;;;OAGG;IACH,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAEvC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -94,6 +94,7 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
94
94
|
* @returns {Promise<DisTubeVoice>}
|
|
95
95
|
*/
|
|
96
96
|
async join(channel) {
|
|
97
|
+
var _a;
|
|
97
98
|
const TIMEOUT = 30e3;
|
|
98
99
|
if (channel) {
|
|
99
100
|
this.channel = channel;
|
|
@@ -106,6 +107,8 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
106
107
|
this.connection.destroy();
|
|
107
108
|
}
|
|
108
109
|
this.voices.delete(this.id);
|
|
110
|
+
if ((_a = this.voiceState) === null || _a === void 0 ? void 0 : _a.connection)
|
|
111
|
+
throw new __1.DisTubeError("VOICE_DEPRECATED_CONNECTION");
|
|
109
112
|
throw new __1.DisTubeError("VOICE_CONNECT_FAILED", TIMEOUT / 1e3);
|
|
110
113
|
}
|
|
111
114
|
return this;
|
|
@@ -115,21 +118,28 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
115
118
|
* @param {Error} [error] Optional, an error to emit with 'error' event.
|
|
116
119
|
*/
|
|
117
120
|
leave(error) {
|
|
121
|
+
var _a, _b;
|
|
118
122
|
this.stop();
|
|
119
123
|
if (!this.isDisconnected) {
|
|
120
124
|
this.emit("disconnect", error);
|
|
121
125
|
this.isDisconnected = true;
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
this.
|
|
127
|
+
(0, voice_1.entersState)(this.audioPlayer, voice_1.AudioPlayerStatus.Idle, ((_b = (_a = this.audioResource) === null || _a === void 0 ? void 0 : _a.silencePaddingFrames) !== null && _b !== void 0 ? _b : 5) * 20)
|
|
128
|
+
.catch(() => this.stop(true))
|
|
129
|
+
.finally(() => {
|
|
130
|
+
if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed)
|
|
131
|
+
this.connection.destroy();
|
|
132
|
+
});
|
|
125
133
|
this.voices.delete(this.id);
|
|
126
134
|
}
|
|
127
135
|
/**
|
|
128
136
|
* Stop the playing stream
|
|
137
|
+
* @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
|
|
138
|
+
* even if the {@link DisTubeVoice#audioResource} has silence padding frames.
|
|
129
139
|
* @private
|
|
130
140
|
*/
|
|
131
|
-
stop() {
|
|
132
|
-
this.audioPlayer.stop();
|
|
141
|
+
stop(force = false) {
|
|
142
|
+
this.audioPlayer.stop(force);
|
|
133
143
|
}
|
|
134
144
|
/**
|
|
135
145
|
* Play a readable stream
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAClD,6BAAsF;AACtF,4CAQ0B;AAK1B;;GAEG;AACH,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAAoC;QACjF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;QACrF,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,gBAAY,CAAC,YAAY,CAAC,CAAC;;gBAClD,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,IAAA,yBAAiB,GAAE;aACnC,EAAE,CAAC,yBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;YACrC,IAAI,QAAQ,CAAC,MAAM,KAAK,yBAAiB,CAAC,IAAI,EAAE;gBAC9C,OAAO,IAAI,CAAC,aAAa,CAAC;gBAC1B,IAA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U,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,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;;;;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,MAAA,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,KAAK,0CAAE,EAAE,0CAAE,KAAK,CAAC;IACxC,CAAC;CACF;AA1ND,oCA0NC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, createDiscordJSAdapter, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n entersState,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, StageChannel, VoiceChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n id: Snowflake;\n voices: DisTubeVoiceManager;\n audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected: boolean;\n private _channel!: VoiceChannel | StageChannel;\n private _volume: number;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceChannel | StageChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.isDisconnected = false;\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._volume = 0.5;\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: VoiceChannel | StageChannel) {\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\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 private _join(channel: VoiceChannel | StageChannel) {\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.VoiceChannel|Discord.StageChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceChannel | StageChannel): 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 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();\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 * @private\n */\n stop() {\n this.audioPlayer.stop();\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 / 100;\n this.audioResource?.volume?.setVolume(Math.pow(this._volume, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this._volume * 100;\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\nexport default DisTubeVoice;\n"]}
|
|
1
|
+
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAClD,6BAAsF;AACtF,4CAQ0B;AAK1B;;GAEG;AACH,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAAoC;QACjF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;QACrF,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,gBAAY,CAAC,YAAY,CAAC,CAAC;;gBAClD,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,IAAA,yBAAiB,GAAE;aACnC,EAAE,CAAC,yBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;YACrC,IAAI,QAAQ,CAAC,M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,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;AAjOD,oCAiOC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, createDiscordJSAdapter, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n entersState,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, StageChannel, VoiceChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n id: Snowflake;\n voices: DisTubeVoiceManager;\n audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected: boolean;\n private _channel!: VoiceChannel | StageChannel;\n private _volume: number;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceChannel | StageChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.isDisconnected = false;\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._volume = 0.5;\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: VoiceChannel | StageChannel) {\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\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 private _join(channel: VoiceChannel | StageChannel) {\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.VoiceChannel|Discord.StageChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceChannel | StageChannel): 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();\n if (!this.isDisconnected) {\n this.emit(\"disconnect\", error);\n this.isDisconnected = true;\n }\n entersState(this.audioPlayer, AudioPlayerStatus.Idle, (this.audioResource?.silencePaddingFrames ?? 5) * 20)\n .catch(() => this.stop(true))\n .finally(() => {\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) this.connection.destroy();\n });\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 / 100;\n this.audioResource?.volume?.setVolume(Math.pow(this._volume, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this._volume * 100;\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\nexport default DisTubeVoice;\n"]}
|
|
@@ -4,6 +4,7 @@ declare const ERROR_MESSAGES: {
|
|
|
4
4
|
EMPTY_ARRAY: (name: string) => string;
|
|
5
5
|
EMPTY_FILTERED_ARRAY: (name: string, type: string) => string;
|
|
6
6
|
INVALID_KEY: (obj: string, key: string) => string;
|
|
7
|
+
EMPTY_STRING: (name: string) => string;
|
|
7
8
|
MISSING_INTENTS: (i: string) => string;
|
|
8
9
|
DISABLED_OPTION: (o: string) => string;
|
|
9
10
|
ENABLED_OPTION: (o: string) => string;
|
|
@@ -14,6 +15,7 @@ declare const ERROR_MESSAGES: {
|
|
|
14
15
|
VOICE_MISSING_PERMS: string;
|
|
15
16
|
VOICE_RECONNECT_FAILED: string;
|
|
16
17
|
VOICE_CHANGE_GUILD: string;
|
|
18
|
+
VOICE_DEPRECATED_CONNECTION: string;
|
|
17
19
|
NO_QUEUE: string;
|
|
18
20
|
QUEUE_EXIST: string;
|
|
19
21
|
ADD_BEFORE_PLAYING: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeError.d.ts","sourceRoot":"","sources":["../../src/struct/DisTubeError.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc;6BACO,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,OAAO,GAAG;
|
|
1
|
+
{"version":3,"file":"DisTubeError.d.ts","sourceRoot":"","sources":["../../src/struct/DisTubeError.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc;6BACO,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,OAAO,GAAG;2BAI5D,MAAM,YAAY,MAAM,SAAS,MAAM;wBAC1C,MAAM;iCACG,MAAM,QAAQ,MAAM;uBAC9B,MAAM,OAAO,MAAM;yBACjB,MAAM;yBAEN,MAAM;yBACN,MAAM;wBACP,MAAM;;;;8BAKA,MAAM;;;;;;;;;;;;;;;;;;;;;6BAyBP,MAAM;;;;CAMhC,CAAC;AAEF,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC;AAC3C,aAAK,UAAU,GAAG,MAAM,aAAa,CAAC;AACtC,aAAK,SAAS,GAAG;KAAG,CAAC,IAAI,UAAU,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,UAAU,CAAC,CAAC;AAClG,aAAK,iBAAiB,GAAG,OAAO,CAAC,MAAM,OAAO,cAAc,EAAE,SAAS,CAAC,CAAC;AAMzE,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,KAAK;IACvD,SAAS,EAAE,MAAM,CAAC;gBACN,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,CAAC,SAAS,iBAAiB,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,CAAC;gBAC9F,IAAI,EAAE,iBAAiB,EAAE,CAAC,EAAE,KAAK;gBACjC,IAAI,EAAE,CAAC,SAAS,UAAU,GAAG,6BAA6B,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM;IAS3F,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,WAEP;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -3,19 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DisTubeError = void 0;
|
|
4
4
|
const ERROR_MESSAGES = {
|
|
5
5
|
INVALID_TYPE: (expected, got, name) => {
|
|
6
|
-
var _a;
|
|
7
|
-
return `Expected ${Array.isArray(expected) ? expected.map(e => (typeof e === "number" ? e : `'${e}'`)).join(" or ") : `'${expected}'`}${name ? ` for '${name}'` : ""}, but got ${
|
|
8
|
-
? `'${got}'`
|
|
9
|
-
: typeof got === "number"
|
|
10
|
-
? got
|
|
11
|
-
: Array.isArray(got)
|
|
12
|
-
? `Array<${got.length}>`
|
|
13
|
-
: ((_a = got === null || got === void 0 ? void 0 : got.constructor) === null || _a === void 0 ? void 0 : _a.name) || typeof got} (${typeof got})`;
|
|
6
|
+
var _a, _b;
|
|
7
|
+
return `Expected ${Array.isArray(expected) ? expected.map(e => (typeof e === "number" ? e : `'${e}'`)).join(" or ") : `'${expected}'`}${name ? ` for '${name}'` : ""}, but got ${JSON.stringify(got)} (${(_b = (_a = got === null || got === void 0 ? void 0 : got.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : typeof got})`;
|
|
14
8
|
},
|
|
15
9
|
NUMBER_COMPARE: (name, expected, value) => `'${name}' must be ${expected} ${value}`,
|
|
16
10
|
EMPTY_ARRAY: (name) => `'${name}' is an empty array`,
|
|
17
11
|
EMPTY_FILTERED_ARRAY: (name, type) => `There is no valid '${type}' in the '${name}' array`,
|
|
18
12
|
INVALID_KEY: (obj, key) => `'${key}' does not need to be provided in ${obj}`,
|
|
13
|
+
EMPTY_STRING: (name) => `'${name}' string must not be empty`,
|
|
19
14
|
MISSING_INTENTS: (i) => `${i} intent must be provided for the Client`,
|
|
20
15
|
DISABLED_OPTION: (o) => `DisTubeOptions.${o} is disabled`,
|
|
21
16
|
ENABLED_OPTION: (o) => `DisTubeOptions.${o} is enabled`,
|
|
@@ -26,6 +21,8 @@ const ERROR_MESSAGES = {
|
|
|
26
21
|
VOICE_MISSING_PERMS: "You do not have permission to join this voice channel",
|
|
27
22
|
VOICE_RECONNECT_FAILED: "Cannot reconnect to the voice channel",
|
|
28
23
|
VOICE_CHANGE_GUILD: "Cannot join a channel in a different guild",
|
|
24
|
+
VOICE_DEPRECATED_CONNECTION: "Cannot connect to the voice channel due to a deprecated connection is created.\n" +
|
|
25
|
+
"Read more: https://distube.js.org/guide/additional-info/update.html#voice",
|
|
29
26
|
NO_QUEUE: "There is no playing queue in this guild",
|
|
30
27
|
QUEUE_EXIST: "This guild has a Queue already",
|
|
31
28
|
ADD_BEFORE_PLAYING: "Cannot add Song before the playing Song",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeError.js","sourceRoot":"","sources":["../../src/struct/DisTubeError.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG;IACrB,YAAY,EAAE,CAAC,QAA0D,EAAE,GAAQ,EAAE,IAAa,EAAE,EA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2B;IAC9C,mBAAmB,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,kBAAkB,CAAC,YAAY;IACnE,aAAa,EAAE,iEAAiE;IAChF,uBAAuB,EACrB,2CAA2C;QAC3C,+EAA+E;IACjF,cAAc,EAAE,yCAAyC;CAC1D,CAAC;AAOF,MAAM,MAAM,GAAG,CAAC,GAAqC,EAAE,GAAG,IAAS,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAEvH,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAsB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAElG,MAAa,YAA+B,SAAQ,KAAK;IAMvD,YAAY,IAAY,EAAE,GAAG,IAAS;QACpC,IAAI,QAAQ,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;;YAC5D,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QAEpB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,KAAK,CAAC,iBAAiB;YAAE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,IAAI;QACN,OAAO,iBAAiB,IAAI,CAAC,SAAS,GAAG,CAAC;IAC5C,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AArBD,oCAqBC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["const ERROR_MESSAGES = {\n INVALID_TYPE: (expected: (number | string) | readonly (number | string)[], got: any, name?: string) =>\n `Expected ${\n Array.isArray(expected) ? expected.map(e => (typeof e === \"number\" ? e : `'${e}'`)).join(\" or \") : `'${expected}'`\n }${name ? ` for '${name}'` : \"\"}, but got ${JSON.stringify(got)} (${got?.constructor?.name ?? typeof got})`,\n NUMBER_COMPARE: (name: string, expected: string, value: number) => `'${name}' must be ${expected} ${value}`,\n EMPTY_ARRAY: (name: string) => `'${name}' is an empty array`,\n EMPTY_FILTERED_ARRAY: (name: string, type: string) => `There is no valid '${type}' in the '${name}' array`,\n INVALID_KEY: (obj: string, key: string) => `'${key}' does not need to be provided in ${obj}`,\n EMPTY_STRING: (name: string) => `'${name}' string must not be empty`,\n\n MISSING_INTENTS: (i: string) => `${i} intent must be provided for the Client`,\n DISABLED_OPTION: (o: string) => `DisTubeOptions.${o} is disabled`,\n ENABLED_OPTION: (o: string) => `DisTubeOptions.${o} is enabled`,\n\n NOT_IN_VOICE: \"User is not in any voice channel\",\n NOT_SUPPORTED_VOICE: \"DisTubeVoice only supports VoiceChannel or a StageChannel\",\n VOICE_FULL: \"The voice channel is full\",\n VOICE_CONNECT_FAILED: (s: number) => `Cannot connect to the voice channel after ${s} seconds`,\n VOICE_MISSING_PERMS: \"You do not have permission to join this voice channel\",\n VOICE_RECONNECT_FAILED: \"Cannot reconnect to the voice channel\",\n VOICE_CHANGE_GUILD: \"Cannot join a channel in a different guild\",\n VOICE_DEPRECATED_CONNECTION:\n \"Cannot connect to the voice channel due to a deprecated connection is created.\\n\" +\n \"Read more: https://distube.js.org/guide/additional-info/update.html#voice\",\n\n NO_QUEUE: \"There is no playing queue in this guild\",\n QUEUE_EXIST: \"This guild has a Queue already\",\n ADD_BEFORE_PLAYING: \"Cannot add Song before the playing Song\",\n PAUSED: \"The queue has been paused already\",\n RESUMED: \"The queue has been playing already\",\n NO_PREVIOUS: \"There is no previous song in this queue\",\n NO_UP_NEXT: \"There is no up next song\",\n NO_SONG_POSITION: \"Does not have any song at this position\",\n NO_PLAYING: \"There is no playing song in the queue\",\n\n NO_RESULT: \"No result found\",\n NO_RELATED: \"Cannot find any related songs\",\n CANNOT_PLAY_RELATED: \"Cannot play the related song\",\n UNAVAILABLE_VIDEO: \"This video is unavailable\",\n UNPLAYABLE_FORMATS: \"No playable format found\",\n NON_NSFW: \"Cannot play age-restricted content in non-NSFW channel\",\n NOT_SUPPORTED_URL: \"This url is not supported\",\n CANNOT_RESOLVE_SONG: (t: string) => `Cannot resolve ${t} to a Song`,\n NO_VALID_SONG: \"'songs' array does not have any valid Song, SearchResult or url\",\n EMPTY_FILTERED_PLAYLIST:\n \"There is no valid video in the playlist\\n\" +\n \"Maybe age-restricted contents is filtered because you are in non-NSFW channel\",\n EMPTY_PLAYLIST: \"There is no valid video in the playlist\",\n};\n\ntype ErrorMessages = typeof ERROR_MESSAGES;\ntype ErrorCodes = keyof ErrorMessages;\ntype ErrorCode = { [K in ErrorCodes]-?: ErrorMessages[K] extends string ? K : never }[ErrorCodes];\ntype ErrorCodeTemplate = Exclude<keyof typeof ERROR_MESSAGES, ErrorCode>;\n\nconst errMsg = (msg: string | ((...x: any) => string), ...args: any) => (typeof msg === \"string\" ? msg : msg(...args));\n\nconst haveCode = (code: string): code is ErrorCodes => Object.keys(ERROR_MESSAGES).includes(code);\n\nexport class DisTubeError<T extends string> extends Error {\n errorCode: string;\n constructor(code: ErrorCode);\n constructor(code: T extends ErrorCodeTemplate ? T : never, ...args: Parameters<ErrorMessages[typeof code]>);\n constructor(code: ErrorCodeTemplate, _: never);\n constructor(code: T extends ErrorCodes ? \"This is built-in error code\" : T, message: string);\n constructor(code: string, ...args: any) {\n if (haveCode(code)) super(errMsg(ERROR_MESSAGES[code], ...args));\n else super(...args);\n\n this.errorCode = code;\n if (Error.captureStackTrace) Error.captureStackTrace(this, DisTubeError);\n }\n\n get name() {\n return `DisTubeError [${this.errorCode}]`;\n }\n\n get code() {\n return this.errorCode;\n }\n}\n\nexport default DisTubeError;\n"]}
|
package/dist/struct/Queue.js
CHANGED
|
@@ -440,9 +440,10 @@ class Queue extends core_1.DisTubeBase {
|
|
|
440
440
|
await this.taskQueue.queuing();
|
|
441
441
|
try {
|
|
442
442
|
this.stopped = true;
|
|
443
|
-
this.voice.stop();
|
|
444
443
|
if (this.options.leaveOnStop)
|
|
445
444
|
this.voice.leave();
|
|
445
|
+
else
|
|
446
|
+
this.voice.stop();
|
|
446
447
|
this.delete();
|
|
447
448
|
}
|
|
448
449
|
finally {
|
package/dist/struct/Queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../../src/struct/Queue.ts"],"names":[],"mappings":";;;AAAA,kCAAsC;AACtC,0BAA+E;AAI/E;;;GAGG;AACH,MAAa,KAAM,SAAQ,kBAAW;IA0EpC;;;;;;OAMG;IACH,YAAY,OAAgB,EAAE,KAAmB,EAAE,IAAmB,EAAE,WAAyB;;QAC/F,KAAK,CAAC,OAAO,CAAC,CAAC;QACf;;;WAGG;QACH,IAAI,CAAC,YAAY,GAAG,MAAA,KAAK,CAAC,OAAO,CAAC,KAAK,0CAAE,EAAiB,CAAC;QAC3D;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB;;;WAGG;QACH,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACnB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtD;;;WAGG;QACH,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB;;;;WAIG;QACH,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB;;;;WAIG;QACH,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB;;;;WAIG;QACH,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB;;;WAGG;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CA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C;QAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD;;;OAGG;IACH,cAAc;QACZ,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAtfD,sBAsfC;AAED,kBAAe,KAAK,CAAC","sourcesContent":["import { DisTubeBase } from \"../core\";\nimport { DisTubeError, RepeatMode, Song, TaskQueue, formatDuration } from \"..\";\nimport type { GuildMember, Snowflake, TextChannel } from \"discord.js\";\nimport type { DisTube, DisTubeVoice, DisTubeVoiceEvents, SearchResult } from \"..\";\n\n/**\n * Represents a queue.\n * @extends DisTubeBase\n */\nexport class Queue extends DisTubeBase {\n id: Snowflake;\n /**\n * Voice connection of this queue\n */\n voice: DisTubeVoice;\n /**\n * List of songs in the queue (The first one is the playing song)\n */\n songs: Song[];\n /**\n * List of the previous songs.\n */\n previousSongs: Song[];\n /**\n * Whether stream is currently stopped.\n * @private\n */\n stopped: boolean;\n /**\n * Whether or not the last song was skipped to next song.\n * @private\n */\n next: boolean;\n /**\n * Whether or not the last song was skipped to previous song.\n * @private\n */\n prev: boolean;\n /**\n * Whether or not the stream is currently playing.\n */\n playing: boolean;\n /**\n * Whether or not the stream is currently paused.\n */\n paused: boolean;\n /**\n * Type of repeat mode (`0` is disabled, `1` is repeating a song, `2` is repeating all the queue).\n * Default value: `0` (disabled)\n */\n repeatMode: RepeatMode;\n /**\n * Whether or not the autoplay mode is enabled.\n * Default value: `false`\n */\n autoplay: boolean;\n /**\n * Enabled audio filters.\n * Available filters: {@link Filters}\n */\n filters: string[];\n /**\n * What time in the song to begin (in seconds).\n */\n beginTime: number;\n /**\n * The text channel of the Queue. (Default: where the first command is called).\n */\n textChannel?: TextChannel;\n /**\n * Timeout for checking empty channel\n * @private\n */\n emptyTimeout?: NodeJS.Timeout;\n /**\n * The client user as a `GuildMember` of this queue's guild\n */\n clientMember: GuildMember;\n /**\n * Task queuing system\n */\n taskQueue: TaskQueue;\n listeners?: DisTubeVoiceEvents;\n /**\n * Create a queue for the guild\n * @param {DisTube} distube DisTube\n * @param {DisTubeVoice} voice Voice connection\n * @param {Song|Song[]} song First song(s)\n * @param {Discord.TextChannel?} textChannel Default text channel\n */\n constructor(distube: DisTube, voice: DisTubeVoice, song: Song | Song[], textChannel?: TextChannel) {\n super(distube);\n /**\n * The client user as a `GuildMember` of this queue's guild\n * @type {Discord.GuildMember}\n */\n this.clientMember = voice.channel.guild?.me as GuildMember;\n /**\n * Voice connection of this queue.\n * @type {DisTubeVoice}\n */\n this.voice = voice;\n /**\n * Queue id (Guild id)\n * @type {Discord.Snowflake}\n */\n this.id = voice.id;\n /**\n * Get or set the stream volume. Default value: `50`.\n * @type {number}\n */\n this.volume = 50;\n /**\n * List of songs in the queue (The first one is the playing song)\n * @type {Array<Song>}\n */\n this.songs = Array.isArray(song) ? [...song] : [song];\n /**\n * List of the previous songs.\n * @type {Array<Song>}\n */\n this.previousSongs = [];\n /**\n * Whether stream is currently stopped.\n * @type {boolean}\n * @private\n */\n this.stopped = false;\n /**\n * Whether or not the last song was skipped to next song.\n * @type {boolean}\n * @private\n */\n this.next = false;\n /**\n * Whether or not the last song was skipped to previous song.\n * @type {boolean}\n * @private\n */\n this.prev = false;\n /**\n * Whether or not the stream is currently playing.\n * @type {boolean}\n */\n this.playing = true;\n /**\n * Whether or not the stream is currently paused.\n * @type {boolean}\n */\n this.paused = false;\n /**\n * Type of repeat mode (`0` is disabled, `1` is repeating a song, `2` is repeating all the queue).\n * Default value: `0` (disabled)\n * @type {RepeatMode}\n */\n this.repeatMode = RepeatMode.DISABLED;\n /**\n * Whether or not the autoplay mode is enabled.\n * Default value: `false`\n * @type {boolean}\n */\n this.autoplay = false;\n /**\n * Enabled audio filters.\n * Available filters: {@link Filters}\n * @type {Array<string>}\n */\n this.filters = [];\n /**\n * What time in the song to begin (in seconds).\n * @type {number}\n */\n this.beginTime = 0;\n /**\n * The text channel of the Queue. (Default: where the first command is called).\n * @type {Discord.TextChannel?}\n */\n this.textChannel = textChannel;\n /**\n * Timeout for checking empty channel\n * @type {*}\n * @private\n */\n this.emptyTimeout = undefined;\n /**\n * Task queuing system\n * @type {TaskQueue}\n * @private\n */\n this.taskQueue = new TaskQueue();\n /**\n * DisTubeVoice listener\n * @type {Object}\n * @private\n */\n this.listeners = undefined;\n }\n /**\n * Formatted duration string.\n * @type {string}\n */\n get formattedDuration() {\n return formatDuration(this.duration);\n }\n /**\n * Queue's duration.\n * @type {number}\n */\n get duration() {\n return this.songs.length ? this.songs.reduce((prev, next) => prev + next.duration, 0) : 0;\n }\n /**\n * What time in the song is playing (in seconds).\n * @type {number}\n */\n get currentTime() {\n return this.voice.playbackDuration + this.beginTime;\n }\n /**\n * Formatted {@link Queue#currentTime} string.\n * @type {string}\n */\n get formattedCurrentTime() {\n return formatDuration(this.currentTime);\n }\n /**\n * The voice channel playing in.\n * @type {Discord.VoiceChannel|Discord.StageChannel|null}\n */\n get voiceChannel() {\n return this.clientMember.voice.channel;\n }\n get volume() {\n return this.voice.volume;\n }\n set volume(value: number) {\n this.voice.volume = value;\n }\n /**\n * Add a Song or an array of Song to the queue\n * @param {Song|Song[]} song Song to add\n * @param {number} [position=-1] Position to add, < 0 to add to the end of the queue\n * @param {boolean} [queuing=true] Wether or not waiting for unfinished tasks\n * @throws {Error}\n * @returns {Queue} The guild queue\n */\n addToQueue(song: Song | SearchResult | (Song | SearchResult)[], position = -1): Queue {\n const isArray = Array.isArray(song);\n if (!song || (isArray && !(song as Song[]).length)) {\n throw new DisTubeError(\"INVALID_TYPE\", [\"Song\", \"SearchResult\", \"Array<Song|SearchResult>\"], song, \"song\");\n }\n if (position === 0) throw new DisTubeError(\"ADD_BEFORE_PLAYING\");\n if (position < 0) {\n if (isArray) this.songs.push(...(song as Song[]));\n else this.songs.push(song as Song);\n } else if (isArray) {\n this.songs.splice(position, 0, ...(song as Song[]));\n } else {\n this.songs.splice(position, 0, song as Song);\n }\n if (isArray) (song as Song[]).map(s => delete s.formats);\n else delete (song as Song).formats;\n return this;\n }\n /**\n * Pause the guild stream\n * @returns {Queue} The guild queue\n */\n pause(): Queue {\n if (this.paused) throw new DisTubeError(\"PAUSED\");\n this.playing = false;\n this.paused = true;\n this.voice.pause();\n return this;\n }\n /**\n * Resume the guild stream\n * @returns {Queue} The guild queue\n */\n resume(): Queue {\n if (this.playing) throw new DisTubeError(\"RESUMED\");\n this.playing = true;\n this.paused = false;\n this.voice.unpause();\n return this;\n }\n /**\n * Set the guild stream's volume\n * @param {number} percent The percentage of volume you want to set\n * @returns {Queue} The guild queue\n */\n setVolume(percent: number): Queue {\n this.volume = percent;\n return this;\n }\n\n /**\n * Skip the playing song if there is a next song in the queue.\n * <info>If {@link Queue#autoplay} is `true` and there is no up next song,\n * DisTube will add and play a related song.</info>\n * @returns {Promise<Song>} The song will skip to\n * @throws {Error}\n */\n async skip(): Promise<Song> {\n await this.taskQueue.queuing();\n try {\n if (this.songs.length <= 1) {\n if (this.autoplay) await this.addRelatedSong();\n else throw new DisTubeError(\"NO_UP_NEXT\");\n }\n const song = this.songs[1];\n this.next = true;\n this.voice.stop();\n return song;\n } finally {\n this.taskQueue.resolve();\n }\n }\n\n /**\n * Play the previous song if exists\n * @returns {Song} The guild queue\n * @throws {Error}\n */\n async previous(): Promise<Song> {\n await this.taskQueue.queuing();\n try {\n if (!this.options.savePreviousSongs) throw new DisTubeError(\"DISABLED_OPTION\", \"savePreviousSongs\");\n if (this.previousSongs?.length === 0 && this.repeatMode !== RepeatMode.QUEUE) {\n throw new DisTubeError(\"NO_PREVIOUS\");\n }\n const song =\n this.repeatMode === 2 ? this.songs[this.songs.length - 1] : this.previousSongs[this.previousSongs.length - 1];\n this.prev = true;\n this.voice.stop();\n return song;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Shuffle the queue's songs\n * @returns {Promise<Queue>} The guild queue\n */\n async shuffle(): Promise<Queue> {\n await this.taskQueue.queuing();\n try {\n if (!this.songs.length) return this;\n const playing = this.songs.shift() as Song;\n for (let i = this.songs.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [this.songs[i], this.songs[j]] = [this.songs[j], this.songs[i]];\n }\n this.songs.unshift(playing);\n return this;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Jump to the song position in the queue.\n * The next one is 1, 2,...\n * The previous one is -1, -2,...\n * @param {number} position The song position to play\n * @returns {Promise<Queue>} The guild queue\n * @throws {Error} if `num` is invalid number\n */\n async jump(position: number): Promise<Queue> {\n await this.taskQueue.queuing();\n try {\n if (typeof position !== \"number\") throw new DisTubeError(\"INVALID_TYPE\", \"number\", position, \"position\");\n if (!position || position > this.songs.length || -position > this.previousSongs.length) {\n throw new DisTubeError(\"NO_SONG_POSITION\");\n }\n if (position > 0) {\n const nextSongs = this.songs.splice(position - 1);\n if (this.options.savePreviousSongs) {\n this.previousSongs.push(...this.songs);\n } else {\n this.previousSongs.push(\n ...this.songs.map(s => {\n return { id: s.id } as Song;\n }),\n );\n }\n this.songs = nextSongs;\n this.next = true;\n } else if (!this.options.savePreviousSongs) {\n throw new DisTubeError(\"DISABLED_OPTION\", \"savePreviousSongs\");\n } else {\n this.prev = true;\n if (position !== -1) this.songs.unshift(...this.previousSongs.splice(position + 1));\n }\n this.voice.stop();\n return this;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Set the repeat mode of the guild queue.\\\n * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`\n * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)\n * @returns {RepeatMode} The new repeat mode\n */\n setRepeatMode(mode?: RepeatMode): RepeatMode {\n if (mode !== undefined && !Object.values(RepeatMode).includes(mode)) {\n throw new DisTubeError(\"INVALID_TYPE\", [\"RepeatMode\", \"undefined\"], mode, \"mode\");\n }\n if (mode === undefined) this.repeatMode = (this.repeatMode + 1) % 3;\n else if (this.repeatMode === mode) this.repeatMode = RepeatMode.DISABLED;\n else this.repeatMode = mode;\n return this.repeatMode;\n }\n /**\n * Enable or disable filter(s) of the queue.\n * Available filters: {@link Filters}\n * @param {string|string[]|false} filter A filter name, an array of filter name or `false` to clear all the filters\n * @param {boolean} [force=false] Force enable the input filter(s) even if it's enabled\n * @returns {Array<string>} Enabled filters.\n * @throws {Error}\n */\n setFilter(filter: string | string[] | false, force = false): Array<string> {\n if (Array.isArray(filter)) {\n filter = filter.filter(f => Object.prototype.hasOwnProperty.call(this.distube.filters, f));\n if (!filter.length) throw new DisTubeError(\"EMPTY_FILTERED_ARRAY\", \"filter\", \"filter name\");\n for (const f of filter) {\n if (this.filters.includes(f)) {\n if (!force) this.filters.splice(this.filters.indexOf(f), 1);\n } else {\n this.filters.push(f);\n }\n }\n } else if (filter === false) {\n this.filters = [];\n } else if (!Object.prototype.hasOwnProperty.call(this.distube.filters, filter)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"filter name\", filter, \"filter\");\n } else if (this.filters.includes(filter)) {\n if (!force) this.filters.splice(this.filters.indexOf(filter), 1);\n } else {\n this.filters.push(filter);\n }\n this.beginTime = this.currentTime;\n this.queues.playSong(this);\n return this.filters;\n }\n /**\n * Set the playing time to another position\n * @param {number} time Time in seconds\n * @returns {Queue} The guild queue\n */\n seek(time: number): Queue {\n if (typeof time !== \"number\") throw new DisTubeError(\"INVALID_TYPE\", \"number\", time, \"time\");\n if (isNaN(time) || time < 0) throw new DisTubeError(\"NUMBER_COMPARE\", \"time\", \"bigger or equal to\", 0);\n this.beginTime = time;\n this.queues.playSong(this);\n return this;\n }\n /**\n * Add a related song of the playing song to the queue\n * @returns {Promise<Song>} The added song\n * @throws {Error}\n */\n async addRelatedSong(): Promise<Song> {\n if (!this.songs?.[0]) throw new DisTubeError(\"NO_PLAYING\");\n const related = this.songs[0].related.find(v => !this.previousSongs.map(s => s.id).includes(v.id));\n if (!related || !(related instanceof Song)) throw new DisTubeError(\"NO_RELATED\");\n const song = await this.handler.resolveSong(this.clientMember, related.url);\n if (!(song instanceof Song)) throw new DisTubeError(\"CANNOT_PLAY_RELATED\");\n this.addToQueue(song);\n return song;\n }\n /**\n * Stop the guild stream\n */\n async stop() {\n await this.taskQueue.queuing();\n try {\n this.stopped = true;\n this.voice.stop();\n if (this.options.leaveOnStop) this.voice.leave();\n this.delete();\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Delete the queue from the manager\n * (This does not leave the queue even if {@link DisTubeOptions|DisTubeOptions.leaveOnStop} is enabled)\n * @private\n */\n delete() {\n this.stopped = true;\n this.songs = [];\n this.previousSongs = [];\n if (this.listeners) {\n for (const event of Object.keys(this.listeners) as (keyof DisTubeVoiceEvents)[]) {\n this.voice.removeListener(event, this.listeners[event]);\n }\n }\n this.queues.delete(this.id);\n this.emit(\"deleteQueue\", this);\n }\n /**\n * Toggle autoplay mode\n * @returns {boolean} Autoplay mode state\n */\n toggleAutoplay(): boolean {\n this.autoplay = !this.autoplay;\n return this.autoplay;\n }\n}\n\nexport default Queue;\n"]}
|
|
1
|
+
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../../src/struct/Queue.ts"],"names":[],"mappings":";;;AAAA,kCAAsC;AACtC,0BAA+E;AAI/E;;;GAGG;AACH,MAAa,KAAM,SAAQ,kBAAW;IA0EpC;;;;;;OAMG;IACH,YAAY,OAAgB,EAAE,KAAmB,EAAE,IAAmB,EAAE,WAAyB;;QAC/F,KAAK,CAAC,OAAO,CAAC,CAAC;QACf;;;WAGG;QACH,IAAI,CAAC,YAAY,GAAG,MAAA,KAAK,CAAC,OAAO,CAAC,KAAK,0CAAE,EAAiB,CAAC;QAC3D;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB;;;WAGG;QACH,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACnB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB;;;WAGG;QACH,IAAI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CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAiC,EAAE;gBAC/E,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;aACzD;SACF;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD;;;OAGG;IACH,cAAc;QACZ,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAtfD,sBAsfC;AAED,kBAAe,KAAK,CAAC","sourcesContent":["import { DisTubeBase } from \"../core\";\nimport { DisTubeError, RepeatMode, Song, TaskQueue, formatDuration } from \"..\";\nimport type { GuildMember, Snowflake, TextChannel } from \"discord.js\";\nimport type { DisTube, DisTubeVoice, DisTubeVoiceEvents, SearchResult } from \"..\";\n\n/**\n * Represents a queue.\n * @extends DisTubeBase\n */\nexport class Queue extends DisTubeBase {\n id: Snowflake;\n /**\n * Voice connection of this queue\n */\n voice: DisTubeVoice;\n /**\n * List of songs in the queue (The first one is the playing song)\n */\n songs: Song[];\n /**\n * List of the previous songs.\n */\n previousSongs: Song[];\n /**\n * Whether stream is currently stopped.\n * @private\n */\n stopped: boolean;\n /**\n * Whether or not the last song was skipped to next song.\n * @private\n */\n next: boolean;\n /**\n * Whether or not the last song was skipped to previous song.\n * @private\n */\n prev: boolean;\n /**\n * Whether or not the stream is currently playing.\n */\n playing: boolean;\n /**\n * Whether or not the stream is currently paused.\n */\n paused: boolean;\n /**\n * Type of repeat mode (`0` is disabled, `1` is repeating a song, `2` is repeating all the queue).\n * Default value: `0` (disabled)\n */\n repeatMode: RepeatMode;\n /**\n * Whether or not the autoplay mode is enabled.\n * Default value: `false`\n */\n autoplay: boolean;\n /**\n * Enabled audio filters.\n * Available filters: {@link Filters}\n */\n filters: string[];\n /**\n * What time in the song to begin (in seconds).\n */\n beginTime: number;\n /**\n * The text channel of the Queue. (Default: where the first command is called).\n */\n textChannel?: TextChannel;\n /**\n * Timeout for checking empty channel\n * @private\n */\n emptyTimeout?: NodeJS.Timeout;\n /**\n * The client user as a `GuildMember` of this queue's guild\n */\n clientMember: GuildMember;\n /**\n * Task queuing system\n */\n taskQueue: TaskQueue;\n listeners?: DisTubeVoiceEvents;\n /**\n * Create a queue for the guild\n * @param {DisTube} distube DisTube\n * @param {DisTubeVoice} voice Voice connection\n * @param {Song|Song[]} song First song(s)\n * @param {Discord.TextChannel?} textChannel Default text channel\n */\n constructor(distube: DisTube, voice: DisTubeVoice, song: Song | Song[], textChannel?: TextChannel) {\n super(distube);\n /**\n * The client user as a `GuildMember` of this queue's guild\n * @type {Discord.GuildMember}\n */\n this.clientMember = voice.channel.guild?.me as GuildMember;\n /**\n * Voice connection of this queue.\n * @type {DisTubeVoice}\n */\n this.voice = voice;\n /**\n * Queue id (Guild id)\n * @type {Discord.Snowflake}\n */\n this.id = voice.id;\n /**\n * Get or set the stream volume. Default value: `50`.\n * @type {number}\n */\n this.volume = 50;\n /**\n * List of songs in the queue (The first one is the playing song)\n * @type {Array<Song>}\n */\n this.songs = Array.isArray(song) ? [...song] : [song];\n /**\n * List of the previous songs.\n * @type {Array<Song>}\n */\n this.previousSongs = [];\n /**\n * Whether stream is currently stopped.\n * @type {boolean}\n * @private\n */\n this.stopped = false;\n /**\n * Whether or not the last song was skipped to next song.\n * @type {boolean}\n * @private\n */\n this.next = false;\n /**\n * Whether or not the last song was skipped to previous song.\n * @type {boolean}\n * @private\n */\n this.prev = false;\n /**\n * Whether or not the stream is currently playing.\n * @type {boolean}\n */\n this.playing = true;\n /**\n * Whether or not the stream is currently paused.\n * @type {boolean}\n */\n this.paused = false;\n /**\n * Type of repeat mode (`0` is disabled, `1` is repeating a song, `2` is repeating all the queue).\n * Default value: `0` (disabled)\n * @type {RepeatMode}\n */\n this.repeatMode = RepeatMode.DISABLED;\n /**\n * Whether or not the autoplay mode is enabled.\n * Default value: `false`\n * @type {boolean}\n */\n this.autoplay = false;\n /**\n * Enabled audio filters.\n * Available filters: {@link Filters}\n * @type {Array<string>}\n */\n this.filters = [];\n /**\n * What time in the song to begin (in seconds).\n * @type {number}\n */\n this.beginTime = 0;\n /**\n * The text channel of the Queue. (Default: where the first command is called).\n * @type {Discord.TextChannel?}\n */\n this.textChannel = textChannel;\n /**\n * Timeout for checking empty channel\n * @type {*}\n * @private\n */\n this.emptyTimeout = undefined;\n /**\n * Task queuing system\n * @type {TaskQueue}\n * @private\n */\n this.taskQueue = new TaskQueue();\n /**\n * DisTubeVoice listener\n * @type {Object}\n * @private\n */\n this.listeners = undefined;\n }\n /**\n * Formatted duration string.\n * @type {string}\n */\n get formattedDuration() {\n return formatDuration(this.duration);\n }\n /**\n * Queue's duration.\n * @type {number}\n */\n get duration() {\n return this.songs.length ? this.songs.reduce((prev, next) => prev + next.duration, 0) : 0;\n }\n /**\n * What time in the song is playing (in seconds).\n * @type {number}\n */\n get currentTime() {\n return this.voice.playbackDuration + this.beginTime;\n }\n /**\n * Formatted {@link Queue#currentTime} string.\n * @type {string}\n */\n get formattedCurrentTime() {\n return formatDuration(this.currentTime);\n }\n /**\n * The voice channel playing in.\n * @type {Discord.VoiceChannel|Discord.StageChannel|null}\n */\n get voiceChannel() {\n return this.clientMember.voice.channel;\n }\n get volume() {\n return this.voice.volume;\n }\n set volume(value: number) {\n this.voice.volume = value;\n }\n /**\n * Add a Song or an array of Song to the queue\n * @param {Song|Song[]} song Song to add\n * @param {number} [position=-1] Position to add, < 0 to add to the end of the queue\n * @param {boolean} [queuing=true] Wether or not waiting for unfinished tasks\n * @throws {Error}\n * @returns {Queue} The guild queue\n */\n addToQueue(song: Song | SearchResult | (Song | SearchResult)[], position = -1): Queue {\n const isArray = Array.isArray(song);\n if (!song || (isArray && !(song as Song[]).length)) {\n throw new DisTubeError(\"INVALID_TYPE\", [\"Song\", \"SearchResult\", \"Array<Song|SearchResult>\"], song, \"song\");\n }\n if (position === 0) throw new DisTubeError(\"ADD_BEFORE_PLAYING\");\n if (position < 0) {\n if (isArray) this.songs.push(...(song as Song[]));\n else this.songs.push(song as Song);\n } else if (isArray) {\n this.songs.splice(position, 0, ...(song as Song[]));\n } else {\n this.songs.splice(position, 0, song as Song);\n }\n if (isArray) (song as Song[]).map(s => delete s.formats);\n else delete (song as Song).formats;\n return this;\n }\n /**\n * Pause the guild stream\n * @returns {Queue} The guild queue\n */\n pause(): Queue {\n if (this.paused) throw new DisTubeError(\"PAUSED\");\n this.playing = false;\n this.paused = true;\n this.voice.pause();\n return this;\n }\n /**\n * Resume the guild stream\n * @returns {Queue} The guild queue\n */\n resume(): Queue {\n if (this.playing) throw new DisTubeError(\"RESUMED\");\n this.playing = true;\n this.paused = false;\n this.voice.unpause();\n return this;\n }\n /**\n * Set the guild stream's volume\n * @param {number} percent The percentage of volume you want to set\n * @returns {Queue} The guild queue\n */\n setVolume(percent: number): Queue {\n this.volume = percent;\n return this;\n }\n\n /**\n * Skip the playing song if there is a next song in the queue.\n * <info>If {@link Queue#autoplay} is `true` and there is no up next song,\n * DisTube will add and play a related song.</info>\n * @returns {Promise<Song>} The song will skip to\n * @throws {Error}\n */\n async skip(): Promise<Song> {\n await this.taskQueue.queuing();\n try {\n if (this.songs.length <= 1) {\n if (this.autoplay) await this.addRelatedSong();\n else throw new DisTubeError(\"NO_UP_NEXT\");\n }\n const song = this.songs[1];\n this.next = true;\n this.voice.stop();\n return song;\n } finally {\n this.taskQueue.resolve();\n }\n }\n\n /**\n * Play the previous song if exists\n * @returns {Song} The guild queue\n * @throws {Error}\n */\n async previous(): Promise<Song> {\n await this.taskQueue.queuing();\n try {\n if (!this.options.savePreviousSongs) throw new DisTubeError(\"DISABLED_OPTION\", \"savePreviousSongs\");\n if (this.previousSongs?.length === 0 && this.repeatMode !== RepeatMode.QUEUE) {\n throw new DisTubeError(\"NO_PREVIOUS\");\n }\n const song =\n this.repeatMode === 2 ? this.songs[this.songs.length - 1] : this.previousSongs[this.previousSongs.length - 1];\n this.prev = true;\n this.voice.stop();\n return song;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Shuffle the queue's songs\n * @returns {Promise<Queue>} The guild queue\n */\n async shuffle(): Promise<Queue> {\n await this.taskQueue.queuing();\n try {\n if (!this.songs.length) return this;\n const playing = this.songs.shift() as Song;\n for (let i = this.songs.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [this.songs[i], this.songs[j]] = [this.songs[j], this.songs[i]];\n }\n this.songs.unshift(playing);\n return this;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Jump to the song position in the queue.\n * The next one is 1, 2,...\n * The previous one is -1, -2,...\n * @param {number} position The song position to play\n * @returns {Promise<Queue>} The guild queue\n * @throws {Error} if `num` is invalid number\n */\n async jump(position: number): Promise<Queue> {\n await this.taskQueue.queuing();\n try {\n if (typeof position !== \"number\") throw new DisTubeError(\"INVALID_TYPE\", \"number\", position, \"position\");\n if (!position || position > this.songs.length || -position > this.previousSongs.length) {\n throw new DisTubeError(\"NO_SONG_POSITION\");\n }\n if (position > 0) {\n const nextSongs = this.songs.splice(position - 1);\n if (this.options.savePreviousSongs) {\n this.previousSongs.push(...this.songs);\n } else {\n this.previousSongs.push(\n ...this.songs.map(s => {\n return { id: s.id } as Song;\n }),\n );\n }\n this.songs = nextSongs;\n this.next = true;\n } else if (!this.options.savePreviousSongs) {\n throw new DisTubeError(\"DISABLED_OPTION\", \"savePreviousSongs\");\n } else {\n this.prev = true;\n if (position !== -1) this.songs.unshift(...this.previousSongs.splice(position + 1));\n }\n this.voice.stop();\n return this;\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Set the repeat mode of the guild queue.\\\n * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`\n * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)\n * @returns {RepeatMode} The new repeat mode\n */\n setRepeatMode(mode?: RepeatMode): RepeatMode {\n if (mode !== undefined && !Object.values(RepeatMode).includes(mode)) {\n throw new DisTubeError(\"INVALID_TYPE\", [\"RepeatMode\", \"undefined\"], mode, \"mode\");\n }\n if (mode === undefined) this.repeatMode = (this.repeatMode + 1) % 3;\n else if (this.repeatMode === mode) this.repeatMode = RepeatMode.DISABLED;\n else this.repeatMode = mode;\n return this.repeatMode;\n }\n /**\n * Enable or disable filter(s) of the queue.\n * Available filters: {@link Filters}\n * @param {string|string[]|false} filter A filter name, an array of filter name or `false` to clear all the filters\n * @param {boolean} [force=false] Force enable the input filter(s) even if it's enabled\n * @returns {Array<string>} Enabled filters.\n * @throws {Error}\n */\n setFilter(filter: string | string[] | false, force = false): Array<string> {\n if (Array.isArray(filter)) {\n filter = filter.filter(f => Object.prototype.hasOwnProperty.call(this.distube.filters, f));\n if (!filter.length) throw new DisTubeError(\"EMPTY_FILTERED_ARRAY\", \"filter\", \"filter name\");\n for (const f of filter) {\n if (this.filters.includes(f)) {\n if (!force) this.filters.splice(this.filters.indexOf(f), 1);\n } else {\n this.filters.push(f);\n }\n }\n } else if (filter === false) {\n this.filters = [];\n } else if (!Object.prototype.hasOwnProperty.call(this.distube.filters, filter)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"filter name\", filter, \"filter\");\n } else if (this.filters.includes(filter)) {\n if (!force) this.filters.splice(this.filters.indexOf(filter), 1);\n } else {\n this.filters.push(filter);\n }\n this.beginTime = this.currentTime;\n this.queues.playSong(this);\n return this.filters;\n }\n /**\n * Set the playing time to another position\n * @param {number} time Time in seconds\n * @returns {Queue} The guild queue\n */\n seek(time: number): Queue {\n if (typeof time !== \"number\") throw new DisTubeError(\"INVALID_TYPE\", \"number\", time, \"time\");\n if (isNaN(time) || time < 0) throw new DisTubeError(\"NUMBER_COMPARE\", \"time\", \"bigger or equal to\", 0);\n this.beginTime = time;\n this.queues.playSong(this);\n return this;\n }\n /**\n * Add a related song of the playing song to the queue\n * @returns {Promise<Song>} The added song\n * @throws {Error}\n */\n async addRelatedSong(): Promise<Song> {\n if (!this.songs?.[0]) throw new DisTubeError(\"NO_PLAYING\");\n const related = this.songs[0].related.find(v => !this.previousSongs.map(s => s.id).includes(v.id));\n if (!related || !(related instanceof Song)) throw new DisTubeError(\"NO_RELATED\");\n const song = await this.handler.resolveSong(this.clientMember, related.url);\n if (!(song instanceof Song)) throw new DisTubeError(\"CANNOT_PLAY_RELATED\");\n this.addToQueue(song);\n return song;\n }\n /**\n * Stop the guild stream\n */\n async stop() {\n await this.taskQueue.queuing();\n try {\n this.stopped = true;\n if (this.options.leaveOnStop) this.voice.leave();\n else this.voice.stop();\n this.delete();\n } finally {\n this.taskQueue.resolve();\n }\n }\n /**\n * Delete the queue from the manager\n * (This does not leave the queue even if {@link DisTubeOptions|DisTubeOptions.leaveOnStop} is enabled)\n * @private\n */\n delete() {\n this.stopped = true;\n this.songs = [];\n this.previousSongs = [];\n if (this.listeners) {\n for (const event of Object.keys(this.listeners) as (keyof DisTubeVoiceEvents)[]) {\n this.voice.removeListener(event, this.listeners[event]);\n }\n }\n this.queues.delete(this.id);\n this.emit(\"deleteQueue\", this);\n }\n /**\n * Toggle autoplay mode\n * @returns {boolean} Autoplay mode state\n */\n toggleAutoplay(): boolean {\n this.autoplay = !this.autoplay;\n return this.autoplay;\n }\n}\n\nexport default Queue;\n"]}
|