distube 2.8.18 → 3.0.0-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/README.md +32 -98
- package/dist/DisTube.d.ts +522 -0
- package/dist/DisTube.d.ts.map +1 -0
- package/dist/DisTube.js +794 -0
- package/dist/DisTube.js.map +1 -0
- package/dist/constant.d.ts +130 -0
- package/dist/constant.d.ts.map +1 -0
- package/dist/constant.js +150 -0
- package/dist/constant.js.map +1 -0
- package/dist/core/DisTubeBase.d.ts +55 -0
- package/dist/core/DisTubeBase.d.ts.map +1 -0
- package/dist/core/DisTubeBase.js +76 -0
- package/dist/core/DisTubeBase.js.map +1 -0
- package/dist/core/DisTubeHandler.d.ts +84 -0
- package/dist/core/DisTubeHandler.d.ts.map +1 -0
- package/dist/core/DisTubeHandler.js +311 -0
- package/dist/core/DisTubeHandler.js.map +1 -0
- package/dist/core/DisTubeOptions.d.ts +26 -0
- package/dist/core/DisTubeOptions.d.ts.map +1 -0
- package/dist/core/DisTubeOptions.js +93 -0
- package/dist/core/DisTubeOptions.js.map +1 -0
- package/dist/core/DisTubeStream.d.ts +52 -0
- package/dist/core/DisTubeStream.d.ts.map +1 -0
- package/dist/core/DisTubeStream.js +109 -0
- package/dist/core/DisTubeStream.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +19 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/manager/BaseManager.d.ts +18 -0
- package/dist/core/manager/BaseManager.d.ts.map +1 -0
- package/dist/core/manager/BaseManager.js +44 -0
- package/dist/core/manager/BaseManager.js.map +1 -0
- package/dist/core/manager/QueueManager.d.ts +60 -0
- package/dist/core/manager/QueueManager.d.ts.map +1 -0
- package/dist/core/manager/QueueManager.js +202 -0
- package/dist/core/manager/QueueManager.js.map +1 -0
- package/dist/core/manager/index.d.ts +3 -0
- package/dist/core/manager/index.d.ts.map +1 -0
- package/dist/core/manager/index.js +15 -0
- package/dist/core/manager/index.js.map +1 -0
- package/dist/core/voice/DJSAdapter.d.ts +4 -0
- package/dist/core/voice/DJSAdapter.d.ts.map +1 -0
- package/dist/core/voice/DJSAdapter.js +61 -0
- package/dist/core/voice/DJSAdapter.js.map +1 -0
- package/dist/core/voice/DisTubeVoice.d.ts +83 -0
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -0
- package/dist/core/voice/DisTubeVoice.js +236 -0
- package/dist/core/voice/DisTubeVoice.js.map +1 -0
- package/dist/core/voice/DisTubeVoiceManager.d.ts +41 -0
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -0
- package/dist/core/voice/DisTubeVoiceManager.js +67 -0
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -0
- package/dist/core/voice/index.d.ts +4 -0
- package/dist/core/voice/index.d.ts.map +1 -0
- package/dist/core/voice/index.js +16 -0
- package/dist/core/voice/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/http.d.ts +8 -0
- package/dist/plugin/http.d.ts.map +1 -0
- package/dist/plugin/http.js +20 -0
- package/dist/plugin/http.js.map +1 -0
- package/dist/plugin/https.d.ts +14 -0
- package/dist/plugin/https.d.ts.map +1 -0
- package/dist/plugin/https.js +50 -0
- package/dist/plugin/https.js.map +1 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +16 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/youtube-dl.d.ts +11 -0
- package/dist/plugin/youtube-dl.d.ts.map +1 -0
- package/dist/plugin/youtube-dl.js +75 -0
- package/dist/plugin/youtube-dl.js.map +1 -0
- package/dist/struct/CustomPlugin.d.ts +27 -0
- package/dist/struct/CustomPlugin.d.ts.map +1 -0
- package/dist/struct/CustomPlugin.js +35 -0
- package/dist/struct/CustomPlugin.js.map +1 -0
- package/dist/struct/DisTubeError.d.ts +54 -0
- package/dist/struct/DisTubeError.d.ts.map +1 -0
- package/dist/struct/DisTubeError.js +72 -0
- package/dist/struct/DisTubeError.js.map +1 -0
- package/dist/struct/ExtractorPlugin.d.ts +29 -0
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -0
- package/dist/struct/ExtractorPlugin.js +32 -0
- package/dist/struct/ExtractorPlugin.js.map +1 -0
- package/dist/struct/Playlist.d.ts +42 -0
- package/dist/struct/Playlist.d.ts.map +1 -0
- package/dist/struct/Playlist.js +104 -0
- package/dist/struct/Playlist.js.map +1 -0
- package/dist/struct/Plugin.d.ts +82 -0
- package/dist/struct/Plugin.d.ts.map +1 -0
- package/dist/struct/Plugin.js +108 -0
- package/dist/struct/Plugin.js.map +1 -0
- package/dist/struct/Queue.d.ts +217 -0
- package/dist/struct/Queue.d.ts.map +1 -0
- package/dist/struct/Queue.js +480 -0
- package/dist/struct/Queue.js.map +1 -0
- package/dist/struct/SearchResult.d.ts +28 -0
- package/dist/struct/SearchResult.d.ts.map +1 -0
- package/dist/struct/SearchResult.js +79 -0
- package/dist/struct/SearchResult.js.map +1 -0
- package/dist/struct/Song.d.ts +68 -0
- package/dist/struct/Song.d.ts.map +1 -0
- package/dist/struct/Song.js +229 -0
- package/dist/struct/Song.js.map +1 -0
- package/dist/struct/TaskQueue.d.ts +33 -0
- package/dist/struct/TaskQueue.d.ts.map +1 -0
- package/dist/struct/TaskQueue.js +58 -0
- package/dist/struct/TaskQueue.js.map +1 -0
- package/dist/struct/index.d.ts +10 -0
- package/dist/struct/index.d.ts.map +1 -0
- package/dist/struct/index.js +22 -0
- package/dist/struct/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type.d.ts +159 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +3 -0
- package/dist/type.js.map +1 -0
- package/dist/util.d.ts +47 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +205 -0
- package/dist/util.js.map +1 -0
- package/package.json +50 -24
- package/src/DisTube.js +0 -1121
- package/src/Playlist.js +0 -107
- package/src/Queue.js +0 -120
- package/src/SearchResult.js +0 -81
- package/src/Song.js +0 -135
- package/src/duration.js +0 -39
- package/typings/DisTube.d.ts +0 -635
- package/typings/Playlist.d.ts +0 -73
- package/typings/Queue.d.ts +0 -106
- package/typings/SearchResult.d.ts +0 -59
- package/typings/Song.d.ts +0 -104
- package/typings/duration.d.ts +0 -2
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
/**
|
|
7
|
+
* Represents a queue.
|
|
8
|
+
* @extends DisTubeBase
|
|
9
|
+
*/
|
|
10
|
+
class Queue extends core_1.DisTubeBase {
|
|
11
|
+
/**
|
|
12
|
+
* Create a queue for the guild
|
|
13
|
+
* @param {DisTube} distube DisTube
|
|
14
|
+
* @param {DisTubeVoice} voice Voice connection
|
|
15
|
+
* @param {Song|Song[]} song First song(s)
|
|
16
|
+
* @param {Discord.TextChannel?} textChannel Default text channel
|
|
17
|
+
*/
|
|
18
|
+
constructor(distube, voice, song, textChannel) {
|
|
19
|
+
var _a;
|
|
20
|
+
super(distube);
|
|
21
|
+
/**
|
|
22
|
+
* The client user as a `GuildMember` of this queue's guild
|
|
23
|
+
* @type {Discord.GuildMember}
|
|
24
|
+
*/
|
|
25
|
+
this.clientMember = (_a = voice.channel.guild) === null || _a === void 0 ? void 0 : _a.me;
|
|
26
|
+
/**
|
|
27
|
+
* Voice connection of this queue.
|
|
28
|
+
* @type {DisTubeVoice}
|
|
29
|
+
*/
|
|
30
|
+
this.voice = voice;
|
|
31
|
+
/**
|
|
32
|
+
* Queue id (Guild id)
|
|
33
|
+
* @type {Discord.Snowflake}
|
|
34
|
+
*/
|
|
35
|
+
this.id = voice.id;
|
|
36
|
+
/**
|
|
37
|
+
* Get or set the stream volume. Default value: `50`.
|
|
38
|
+
* @type {number}
|
|
39
|
+
*/
|
|
40
|
+
this.volume = 50;
|
|
41
|
+
/**
|
|
42
|
+
* List of songs in the queue (The first one is the playing song)
|
|
43
|
+
* @type {Array<Song>}
|
|
44
|
+
*/
|
|
45
|
+
this.songs = Array.isArray(song) ? [...song] : [song];
|
|
46
|
+
/**
|
|
47
|
+
* List of the previous songs.
|
|
48
|
+
* @type {Array<Song>}
|
|
49
|
+
*/
|
|
50
|
+
this.previousSongs = [];
|
|
51
|
+
/**
|
|
52
|
+
* Whether stream is currently stopped.
|
|
53
|
+
* @type {boolean}
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
this.stopped = false;
|
|
57
|
+
/**
|
|
58
|
+
* Whether or not the last song was skipped to next song.
|
|
59
|
+
* @type {boolean}
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
this.next = false;
|
|
63
|
+
/**
|
|
64
|
+
* Whether or not the last song was skipped to previous song.
|
|
65
|
+
* @type {boolean}
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
this.prev = false;
|
|
69
|
+
/**
|
|
70
|
+
* Whether or not the stream is currently playing.
|
|
71
|
+
* @type {boolean}
|
|
72
|
+
*/
|
|
73
|
+
this.playing = true;
|
|
74
|
+
/**
|
|
75
|
+
* Whether or not the stream is currently paused.
|
|
76
|
+
* @type {boolean}
|
|
77
|
+
*/
|
|
78
|
+
this.paused = false;
|
|
79
|
+
/**
|
|
80
|
+
* Type of repeat mode (`0` is disabled, `1` is repeating a song, `2` is repeating all the queue).
|
|
81
|
+
* Default value: `0` (disabled)
|
|
82
|
+
* @type {RepeatMode}
|
|
83
|
+
*/
|
|
84
|
+
this.repeatMode = __1.RepeatMode.DISABLED;
|
|
85
|
+
/**
|
|
86
|
+
* Whether or not the autoplay mode is enabled.
|
|
87
|
+
* Default value: `false`
|
|
88
|
+
* @type {boolean}
|
|
89
|
+
*/
|
|
90
|
+
this.autoplay = false;
|
|
91
|
+
/**
|
|
92
|
+
* Enabled audio filters.
|
|
93
|
+
* Available filters: {@link Filters}
|
|
94
|
+
* @type {Array<string>}
|
|
95
|
+
*/
|
|
96
|
+
this.filters = [];
|
|
97
|
+
/**
|
|
98
|
+
* What time in the song to begin (in seconds).
|
|
99
|
+
* @type {number}
|
|
100
|
+
*/
|
|
101
|
+
this.beginTime = 0;
|
|
102
|
+
/**
|
|
103
|
+
* The text channel of the Queue. (Default: where the first command is called).
|
|
104
|
+
* @type {Discord.TextChannel?}
|
|
105
|
+
*/
|
|
106
|
+
this.textChannel = textChannel;
|
|
107
|
+
/**
|
|
108
|
+
* Timeout for checking empty channel
|
|
109
|
+
* @type {*}
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
this.emptyTimeout = undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Task queuing system
|
|
115
|
+
* @type {TaskQueue}
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
this.taskQueue = new __1.TaskQueue();
|
|
119
|
+
/**
|
|
120
|
+
* DisTubeVoice listener
|
|
121
|
+
* @type {Object}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
this.listeners = undefined;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Formatted duration string.
|
|
128
|
+
* @type {string}
|
|
129
|
+
*/
|
|
130
|
+
get formattedDuration() {
|
|
131
|
+
return (0, __1.formatDuration)(this.duration);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Queue's duration.
|
|
135
|
+
* @type {number}
|
|
136
|
+
*/
|
|
137
|
+
get duration() {
|
|
138
|
+
return this.songs.length ? this.songs.reduce((prev, next) => prev + next.duration, 0) : 0;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* What time in the song is playing (in seconds).
|
|
142
|
+
* @type {number}
|
|
143
|
+
*/
|
|
144
|
+
get currentTime() {
|
|
145
|
+
return this.voice.playbackDuration + this.beginTime;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Formatted {@link Queue#currentTime} string.
|
|
149
|
+
* @type {string}
|
|
150
|
+
*/
|
|
151
|
+
get formattedCurrentTime() {
|
|
152
|
+
return (0, __1.formatDuration)(this.currentTime);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The voice channel playing in.
|
|
156
|
+
* @type {Discord.VoiceChannel|Discord.StageChannel|null}
|
|
157
|
+
*/
|
|
158
|
+
get voiceChannel() {
|
|
159
|
+
return this.clientMember.voice.channel;
|
|
160
|
+
}
|
|
161
|
+
get volume() {
|
|
162
|
+
return this.voice.volume;
|
|
163
|
+
}
|
|
164
|
+
set volume(value) {
|
|
165
|
+
this.voice.volume = value;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Add a Song or an array of Song to the queue
|
|
169
|
+
* @param {Song|Song[]} song Song to add
|
|
170
|
+
* @param {number} [position=-1] Position to add, < 0 to add to the end of the queue
|
|
171
|
+
* @param {boolean} [queuing=true] Wether or not waiting for unfinished tasks
|
|
172
|
+
* @throws {Error}
|
|
173
|
+
* @returns {Queue} The guild queue
|
|
174
|
+
*/
|
|
175
|
+
addToQueue(song, position = -1) {
|
|
176
|
+
const isArray = Array.isArray(song);
|
|
177
|
+
if (!song || (isArray && !song.length)) {
|
|
178
|
+
throw new __1.DisTubeError("INVALID_TYPE", ["Song", "SearchResult", "Array<Song|SearchResult>"], song, "song");
|
|
179
|
+
}
|
|
180
|
+
if (position === 0)
|
|
181
|
+
throw new __1.DisTubeError("ADD_BEFORE_PLAYING");
|
|
182
|
+
if (position < 0) {
|
|
183
|
+
if (isArray)
|
|
184
|
+
this.songs.push(...song);
|
|
185
|
+
else
|
|
186
|
+
this.songs.push(song);
|
|
187
|
+
}
|
|
188
|
+
else if (isArray) {
|
|
189
|
+
this.songs.splice(position, 0, ...song);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
this.songs.splice(position, 0, song);
|
|
193
|
+
}
|
|
194
|
+
if (isArray)
|
|
195
|
+
song.map(s => delete s.formats);
|
|
196
|
+
else
|
|
197
|
+
delete song.formats;
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Pause the guild stream
|
|
202
|
+
* @returns {Queue} The guild queue
|
|
203
|
+
*/
|
|
204
|
+
pause() {
|
|
205
|
+
if (this.paused)
|
|
206
|
+
throw new __1.DisTubeError("PAUSED");
|
|
207
|
+
this.playing = false;
|
|
208
|
+
this.paused = true;
|
|
209
|
+
this.voice.pause();
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Resume the guild stream
|
|
214
|
+
* @returns {Queue} The guild queue
|
|
215
|
+
*/
|
|
216
|
+
resume() {
|
|
217
|
+
if (this.playing)
|
|
218
|
+
throw new __1.DisTubeError("RESUMED");
|
|
219
|
+
this.playing = true;
|
|
220
|
+
this.paused = false;
|
|
221
|
+
this.voice.unpause();
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Set the guild stream's volume
|
|
226
|
+
* @param {number} percent The percentage of volume you want to set
|
|
227
|
+
* @returns {Queue} The guild queue
|
|
228
|
+
*/
|
|
229
|
+
setVolume(percent) {
|
|
230
|
+
this.volume = percent;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Skip the playing song if there is a next song in the queue.
|
|
235
|
+
* <info>If {@link Queue#autoplay} is `true` and there is no up next song,
|
|
236
|
+
* DisTube will add and play a related song.</info>
|
|
237
|
+
* @returns {Promise<Song>} The song will skip to
|
|
238
|
+
* @throws {Error}
|
|
239
|
+
*/
|
|
240
|
+
async skip() {
|
|
241
|
+
await this.taskQueue.queuing();
|
|
242
|
+
try {
|
|
243
|
+
if (this.songs.length <= 1) {
|
|
244
|
+
if (this.autoplay)
|
|
245
|
+
await this.addRelatedSong();
|
|
246
|
+
else
|
|
247
|
+
throw new __1.DisTubeError("NO_UP_NEXT");
|
|
248
|
+
}
|
|
249
|
+
const song = this.songs[1];
|
|
250
|
+
this.next = true;
|
|
251
|
+
this.voice.stop();
|
|
252
|
+
return song;
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
this.taskQueue.resolve();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Play the previous song if exists
|
|
260
|
+
* @returns {Song} The guild queue
|
|
261
|
+
* @throws {Error}
|
|
262
|
+
*/
|
|
263
|
+
async previous() {
|
|
264
|
+
var _a;
|
|
265
|
+
await this.taskQueue.queuing();
|
|
266
|
+
try {
|
|
267
|
+
if (!this.options.savePreviousSongs)
|
|
268
|
+
throw new __1.DisTubeError("DISABLED_OPTION", "savePreviousSongs");
|
|
269
|
+
if (((_a = this.previousSongs) === null || _a === void 0 ? void 0 : _a.length) === 0 && this.repeatMode !== __1.RepeatMode.QUEUE) {
|
|
270
|
+
throw new __1.DisTubeError("NO_PREVIOUS");
|
|
271
|
+
}
|
|
272
|
+
const song = this.repeatMode === 2 ? this.songs[this.songs.length - 1] : this.previousSongs[this.previousSongs.length - 1];
|
|
273
|
+
this.prev = true;
|
|
274
|
+
this.voice.stop();
|
|
275
|
+
return song;
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
this.taskQueue.resolve();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Shuffle the queue's songs
|
|
283
|
+
* @returns {Promise<Queue>} The guild queue
|
|
284
|
+
*/
|
|
285
|
+
async shuffle() {
|
|
286
|
+
await this.taskQueue.queuing();
|
|
287
|
+
try {
|
|
288
|
+
if (!this.songs.length)
|
|
289
|
+
return this;
|
|
290
|
+
const playing = this.songs.shift();
|
|
291
|
+
for (let i = this.songs.length - 1; i > 0; i--) {
|
|
292
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
293
|
+
[this.songs[i], this.songs[j]] = [this.songs[j], this.songs[i]];
|
|
294
|
+
}
|
|
295
|
+
this.songs.unshift(playing);
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
this.taskQueue.resolve();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Jump to the song position in the queue.
|
|
304
|
+
* The next one is 1, 2,...
|
|
305
|
+
* The previous one is -1, -2,...
|
|
306
|
+
* @param {number} position The song position to play
|
|
307
|
+
* @returns {Promise<Queue>} The guild queue
|
|
308
|
+
* @throws {Error} if `num` is invalid number
|
|
309
|
+
*/
|
|
310
|
+
async jump(position) {
|
|
311
|
+
await this.taskQueue.queuing();
|
|
312
|
+
try {
|
|
313
|
+
if (typeof position !== "number")
|
|
314
|
+
throw new __1.DisTubeError("INVALID_TYPE", "number", position, "position");
|
|
315
|
+
if (!position || position > this.songs.length || -position > this.previousSongs.length) {
|
|
316
|
+
throw new __1.DisTubeError("NO_SONG_POSITION");
|
|
317
|
+
}
|
|
318
|
+
if (position > 0) {
|
|
319
|
+
const nextSongs = this.songs.splice(position - 1);
|
|
320
|
+
if (this.options.savePreviousSongs) {
|
|
321
|
+
this.previousSongs.push(...this.songs);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
this.previousSongs.push(...this.songs.map(s => {
|
|
325
|
+
return { id: s.id };
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
this.songs = nextSongs;
|
|
329
|
+
this.next = true;
|
|
330
|
+
}
|
|
331
|
+
else if (!this.options.savePreviousSongs) {
|
|
332
|
+
throw new __1.DisTubeError("DISABLED_OPTION", "savePreviousSongs");
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
this.prev = true;
|
|
336
|
+
if (position !== -1)
|
|
337
|
+
this.songs.unshift(...this.previousSongs.splice(position + 1));
|
|
338
|
+
}
|
|
339
|
+
this.voice.stop();
|
|
340
|
+
return this;
|
|
341
|
+
}
|
|
342
|
+
finally {
|
|
343
|
+
this.taskQueue.resolve();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Set the repeat mode of the guild queue.\
|
|
348
|
+
* Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`
|
|
349
|
+
* @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)
|
|
350
|
+
* @returns {RepeatMode} The new repeat mode
|
|
351
|
+
*/
|
|
352
|
+
setRepeatMode(mode) {
|
|
353
|
+
if (mode !== undefined && !Object.values(__1.RepeatMode).includes(mode)) {
|
|
354
|
+
throw new __1.DisTubeError("INVALID_TYPE", ["RepeatMode", "undefined"], mode, "mode");
|
|
355
|
+
}
|
|
356
|
+
if (mode === undefined)
|
|
357
|
+
this.repeatMode = (this.repeatMode + 1) % 3;
|
|
358
|
+
else if (this.repeatMode === mode)
|
|
359
|
+
this.repeatMode = __1.RepeatMode.DISABLED;
|
|
360
|
+
else
|
|
361
|
+
this.repeatMode = mode;
|
|
362
|
+
return this.repeatMode;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Enable or disable filter(s) of the queue.
|
|
366
|
+
* Available filters: {@link Filters}
|
|
367
|
+
* @param {string|string[]|false} filter A filter name, an array of filter name or `false` to clear all the filters
|
|
368
|
+
* @param {boolean} [force=false] Force enable the input filter(s) even if it's enabled
|
|
369
|
+
* @returns {Array<string>} Enabled filters.
|
|
370
|
+
* @throws {Error}
|
|
371
|
+
*/
|
|
372
|
+
setFilter(filter, force = false) {
|
|
373
|
+
if (Array.isArray(filter)) {
|
|
374
|
+
filter = filter.filter(f => Object.prototype.hasOwnProperty.call(this.distube.filters, f));
|
|
375
|
+
if (!filter.length)
|
|
376
|
+
throw new __1.DisTubeError("EMPTY_FILTERED_ARRAY", "filter", "filter name");
|
|
377
|
+
for (const f of filter) {
|
|
378
|
+
if (this.filters.includes(f)) {
|
|
379
|
+
if (!force)
|
|
380
|
+
this.filters.splice(this.filters.indexOf(f), 1);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
this.filters.push(f);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else if (filter === false) {
|
|
388
|
+
this.filters = [];
|
|
389
|
+
}
|
|
390
|
+
else if (!Object.prototype.hasOwnProperty.call(this.distube.filters, filter)) {
|
|
391
|
+
throw new __1.DisTubeError("INVALID_TYPE", "filter name", filter, "filter");
|
|
392
|
+
}
|
|
393
|
+
else if (this.filters.includes(filter)) {
|
|
394
|
+
if (!force)
|
|
395
|
+
this.filters.splice(this.filters.indexOf(filter), 1);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
this.filters.push(filter);
|
|
399
|
+
}
|
|
400
|
+
this.beginTime = this.currentTime;
|
|
401
|
+
this.queues.playSong(this);
|
|
402
|
+
return this.filters;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Set the playing time to another position
|
|
406
|
+
* @param {number} time Time in seconds
|
|
407
|
+
* @returns {Queue} The guild queue
|
|
408
|
+
*/
|
|
409
|
+
seek(time) {
|
|
410
|
+
if (typeof time !== "number")
|
|
411
|
+
throw new __1.DisTubeError("INVALID_TYPE", "number", time, "time");
|
|
412
|
+
if (isNaN(time) || time < 0)
|
|
413
|
+
throw new __1.DisTubeError("NUMBER_COMPARE", "time", "bigger or equal to", 0);
|
|
414
|
+
this.beginTime = time;
|
|
415
|
+
this.queues.playSong(this);
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Add a related song of the playing song to the queue
|
|
420
|
+
* @returns {Promise<Song>} The added song
|
|
421
|
+
* @throws {Error}
|
|
422
|
+
*/
|
|
423
|
+
async addRelatedSong() {
|
|
424
|
+
var _a;
|
|
425
|
+
if (!((_a = this.songs) === null || _a === void 0 ? void 0 : _a[0]))
|
|
426
|
+
throw new __1.DisTubeError("NO_PLAYING");
|
|
427
|
+
const related = this.songs[0].related.find(v => !this.previousSongs.map(s => s.id).includes(v.id));
|
|
428
|
+
if (!related || !(related instanceof __1.Song))
|
|
429
|
+
throw new __1.DisTubeError("NO_RELATED");
|
|
430
|
+
const song = await this.handler.resolveSong(this.clientMember, related.url);
|
|
431
|
+
if (!(song instanceof __1.Song))
|
|
432
|
+
throw new __1.DisTubeError("CANNOT_PLAY_RELATED");
|
|
433
|
+
this.addToQueue(song);
|
|
434
|
+
return song;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Stop the guild stream
|
|
438
|
+
*/
|
|
439
|
+
async stop() {
|
|
440
|
+
await this.taskQueue.queuing();
|
|
441
|
+
try {
|
|
442
|
+
this.stopped = true;
|
|
443
|
+
this.voice.stop();
|
|
444
|
+
if (this.options.leaveOnStop)
|
|
445
|
+
this.voice.leave();
|
|
446
|
+
this.delete();
|
|
447
|
+
}
|
|
448
|
+
finally {
|
|
449
|
+
this.taskQueue.resolve();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Delete the queue from the manager
|
|
454
|
+
* (This does not leave the queue even if {@link DisTubeOptions|DisTubeOptions.leaveOnStop} is enabled)
|
|
455
|
+
* @private
|
|
456
|
+
*/
|
|
457
|
+
delete() {
|
|
458
|
+
this.stopped = true;
|
|
459
|
+
this.songs = [];
|
|
460
|
+
this.previousSongs = [];
|
|
461
|
+
if (this.listeners) {
|
|
462
|
+
for (const event of Object.keys(this.listeners)) {
|
|
463
|
+
this.voice.removeListener(event, this.listeners[event]);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
this.queues.delete(this.id);
|
|
467
|
+
this.emit("deleteQueue", this);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Toggle autoplay mode
|
|
471
|
+
* @returns {boolean} Autoplay mode state
|
|
472
|
+
*/
|
|
473
|
+
toggleAutoplay() {
|
|
474
|
+
this.autoplay = !this.autoplay;
|
|
475
|
+
return this.autoplay;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
exports.Queue = Queue;
|
|
479
|
+
exports.default = Queue;
|
|
480
|
+
//# sourceMappingURL=Queue.js.map
|
|
@@ -0,0 +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,CAAC;QACpB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB;;;;WAIG;QACH,IAAI,CAAC,UAAU,GAAG,cAAU,CAAC,QAAQ,CAAC;QACtC;;;;WAIG;QACH,IAAI,CA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AAC;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"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Playlist, Video } from "@distube/ytsr";
|
|
2
|
+
/** Class representing a search result. */
|
|
3
|
+
export declare class SearchResult {
|
|
4
|
+
source: "youtube";
|
|
5
|
+
type: "video" | "playlist";
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
views?: number;
|
|
10
|
+
isLive?: boolean;
|
|
11
|
+
duration?: number;
|
|
12
|
+
formattedDuration?: string;
|
|
13
|
+
thumbnail?: string;
|
|
14
|
+
/** Video or playlist uploader */
|
|
15
|
+
uploader: {
|
|
16
|
+
/** Uploader name */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Uploader url */
|
|
19
|
+
url?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create a search result
|
|
23
|
+
* @param {Object} info ytsr result
|
|
24
|
+
*/
|
|
25
|
+
constructor(info: Video | Playlist);
|
|
26
|
+
}
|
|
27
|
+
export default SearchResult;
|
|
28
|
+
//# sourceMappingURL=SearchResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchResult.d.ts","sourceRoot":"","sources":["../../src/struct/SearchResult.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAErD,0CAA0C;AAC1C,qBAAa,YAAY;IACvB,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,QAAQ,EAAE;QACR,oBAAoB;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,mBAAmB;QACnB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF;;;OAGG;gBACS,IAAI,EAAE,KAAK,GAAG,QAAQ;CA+DnC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SearchResult = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
/** Class representing a search result. */
|
|
6
|
+
class SearchResult {
|
|
7
|
+
/**
|
|
8
|
+
* Create a search result
|
|
9
|
+
* @param {Object} info ytsr result
|
|
10
|
+
*/
|
|
11
|
+
constructor(info) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
this.source = "youtube";
|
|
14
|
+
/**
|
|
15
|
+
* Type of SearchResult (`video` or `playlist`)
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
this.type = info.type;
|
|
19
|
+
/**
|
|
20
|
+
* YouTube video or playlist id
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
this.id = info.id;
|
|
24
|
+
/**
|
|
25
|
+
* Video or playlist title.
|
|
26
|
+
* @type {string}
|
|
27
|
+
*/
|
|
28
|
+
this.name = info.name;
|
|
29
|
+
/**
|
|
30
|
+
* Video or playlist URL.
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
this.url = info.url;
|
|
34
|
+
if (this.type === "video") {
|
|
35
|
+
info = info;
|
|
36
|
+
/**
|
|
37
|
+
* [Video only] Video or playlist views count
|
|
38
|
+
* @type {number}
|
|
39
|
+
*/
|
|
40
|
+
this.views = info.views;
|
|
41
|
+
/**
|
|
42
|
+
* [Video only] Indicates if the video is an active live.
|
|
43
|
+
* @type {boolean?}
|
|
44
|
+
*/
|
|
45
|
+
this.isLive = info.isLive;
|
|
46
|
+
/**
|
|
47
|
+
* [Video only] Video duration.
|
|
48
|
+
* @type {number}
|
|
49
|
+
*/
|
|
50
|
+
this.duration = this.isLive ? 0 : (0, __1.toSecond)(info.duration);
|
|
51
|
+
/**
|
|
52
|
+
* [Video only] Formatted duration string `hh:mm:ss` or `mm:ss`.
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
55
|
+
this.formattedDuration = this.isLive ? "Live" : (0, __1.formatDuration)(this.duration);
|
|
56
|
+
/**
|
|
57
|
+
* [Video only] Video thumbnail.
|
|
58
|
+
* @type {string?}
|
|
59
|
+
*/
|
|
60
|
+
this.thumbnail = info.thumbnail;
|
|
61
|
+
}
|
|
62
|
+
else if (this.type !== "playlist") {
|
|
63
|
+
throw new __1.DisTubeError("INVALID_TYPE", ["video", "playlist"], this.type, "SearchResult.type");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Song uploader
|
|
67
|
+
* @type {Object}
|
|
68
|
+
* @prop {string?} name Uploader name
|
|
69
|
+
* @prop {string?} url Uploader url
|
|
70
|
+
*/
|
|
71
|
+
this.uploader = {
|
|
72
|
+
name: (_a = (info.author || info.owner)) === null || _a === void 0 ? void 0 : _a.name,
|
|
73
|
+
url: (_b = (info.author || info.owner)) === null || _b === void 0 ? void 0 : _b.url,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SearchResult = SearchResult;
|
|
78
|
+
exports.default = SearchResult;
|
|
79
|
+
//# sourceMappingURL=SearchResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchResult.js","sourceRoot":"","sources":["../../src/struct/SearchResult.ts"],"names":[],"mappings":";;;AAAA,0BAA4D;AAG5D,0CAA0C;AAC1C,MAAa,YAAY;IAkBvB;;;OAGG;IACH,YAAY,IAAsB;;QAChC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB;;;WAGG;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB;;;WAGG;QACH,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB;;;WAGG;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB;;;WAGG;QACH,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE;YACzB,IAAI,GAAG,IAAa,CAAC;YACrB;;;eAGG;YACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB;;;eAGG;YACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;YAC1B;;;eAGG;YACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,YAAQ,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1D;;;eAGG;YACH,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,kBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9E;;;eAGG;YACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;SACjC;aAAM,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;YACnC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;SAC/F;QACD;;;;;WAKG;QACH,IAAI,CAAC,QAAQ,GAAG;YACd,IAAI,EAAE,MAAA,CAAE,IAAc,CAAC,MAAM,IAAK,IAAiB,CAAC,KAAK,CAAC,0CAAE,IAAI;YAChE,GAAG,EAAE,MAAA,CAAE,IAAc,CAAC,MAAM,IAAK,IAAiB,CAAC,KAAK,CAAC,0CAAE,GAAG;SAC/D,CAAC;IACJ,CAAC;CACF;AArFD,oCAqFC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { DisTubeError, formatDuration, toSecond } from \"..\";\nimport type { Playlist, Video } from \"@distube/ytsr\";\n\n/** Class representing a search result. */\nexport class SearchResult {\n source: \"youtube\";\n type: \"video\" | \"playlist\";\n id: string;\n name: string;\n url: string;\n views?: number;\n isLive?: boolean;\n duration?: number;\n formattedDuration?: string;\n thumbnail?: string;\n /** Video or playlist uploader */\n uploader: {\n /** Uploader name */\n name?: string;\n /** Uploader url */\n url?: string;\n };\n /**\n * Create a search result\n * @param {Object} info ytsr result\n */\n constructor(info: Video | Playlist) {\n this.source = \"youtube\";\n /**\n * Type of SearchResult (`video` or `playlist`)\n * @type {string}\n */\n this.type = info.type;\n /**\n * YouTube video or playlist id\n * @type {string}\n */\n this.id = info.id;\n /**\n * Video or playlist title.\n * @type {string}\n */\n this.name = info.name;\n /**\n * Video or playlist URL.\n * @type {string}\n */\n this.url = info.url;\n if (this.type === \"video\") {\n info = info as Video;\n /**\n * [Video only] Video or playlist views count\n * @type {number}\n */\n this.views = info.views;\n /**\n * [Video only] Indicates if the video is an active live.\n * @type {boolean?}\n */\n this.isLive = info.isLive;\n /**\n * [Video only] Video duration.\n * @type {number}\n */\n this.duration = this.isLive ? 0 : toSecond(info.duration);\n /**\n * [Video only] Formatted duration string `hh:mm:ss` or `mm:ss`.\n * @type {string}\n */\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n /**\n * [Video only] Video thumbnail.\n * @type {string?}\n */\n this.thumbnail = info.thumbnail;\n } else if (this.type !== \"playlist\") {\n throw new DisTubeError(\"INVALID_TYPE\", [\"video\", \"playlist\"], this.type, \"SearchResult.type\");\n }\n /**\n * Song uploader\n * @type {Object}\n * @prop {string?} name Uploader name\n * @prop {string?} url Uploader url\n */\n this.uploader = {\n name: ((info as Video).author || (info as Playlist).owner)?.name,\n url: ((info as Video).author || (info as Playlist).owner)?.url,\n };\n }\n}\n\nexport default SearchResult;\n"]}
|