distube 4.0.0-dev.1 → 4.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/DisTube.d.ts +13 -480
  2. package/dist/DisTube.d.ts.map +1 -1
  3. package/dist/DisTube.js +30 -544
  4. package/dist/DisTube.js.map +1 -1
  5. package/dist/constant.d.ts +0 -97
  6. package/dist/constant.d.ts.map +1 -1
  7. package/dist/constant.js +0 -97
  8. package/dist/constant.js.map +1 -1
  9. package/dist/core/DisTubeBase.d.ts +0 -40
  10. package/dist/core/DisTubeBase.d.ts.map +1 -1
  11. package/dist/core/DisTubeBase.js +0 -44
  12. package/dist/core/DisTubeBase.js.map +1 -1
  13. package/dist/core/DisTubeHandler.d.ts +2 -68
  14. package/dist/core/DisTubeHandler.d.ts.map +1 -1
  15. package/dist/core/DisTubeHandler.js +6 -68
  16. package/dist/core/DisTubeHandler.js.map +1 -1
  17. package/dist/core/DisTubeStream.d.ts +0 -33
  18. package/dist/core/DisTubeStream.d.ts.map +1 -1
  19. package/dist/core/DisTubeStream.js +0 -36
  20. package/dist/core/DisTubeStream.js.map +1 -1
  21. package/dist/core/manager/BaseManager.d.ts +1 -16
  22. package/dist/core/manager/BaseManager.d.ts.map +1 -1
  23. package/dist/core/manager/BaseManager.js +2 -28
  24. package/dist/core/manager/BaseManager.js.map +1 -1
  25. package/dist/core/manager/FilterManager.d.ts +16 -0
  26. package/dist/core/manager/FilterManager.d.ts.map +1 -0
  27. package/dist/core/manager/FilterManager.js +88 -0
  28. package/dist/core/manager/FilterManager.js.map +1 -0
  29. package/dist/core/manager/GuildIdManager.d.ts +9 -0
  30. package/dist/core/manager/GuildIdManager.d.ts.map +1 -0
  31. package/dist/core/manager/GuildIdManager.js +25 -0
  32. package/dist/core/manager/GuildIdManager.js.map +1 -0
  33. package/dist/core/manager/QueueManager.d.ts +4 -26
  34. package/dist/core/manager/QueueManager.d.ts.map +1 -1
  35. package/dist/core/manager/QueueManager.js +27 -48
  36. package/dist/core/manager/QueueManager.js.map +1 -1
  37. package/dist/core/manager/index.d.ts +2 -0
  38. package/dist/core/manager/index.d.ts.map +1 -1
  39. package/dist/core/manager/index.js +2 -0
  40. package/dist/core/manager/index.js.map +1 -1
  41. package/dist/core/voice/DisTubeVoice.d.ts +0 -50
  42. package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
  43. package/dist/core/voice/DisTubeVoice.js +8 -68
  44. package/dist/core/voice/DisTubeVoice.js.map +1 -1
  45. package/dist/core/voice/DisTubeVoiceManager.d.ts +2 -33
  46. package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -1
  47. package/dist/core/voice/DisTubeVoiceManager.js +1 -32
  48. package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
  49. package/dist/struct/CustomPlugin.d.ts +0 -41
  50. package/dist/struct/CustomPlugin.d.ts.map +1 -1
  51. package/dist/struct/CustomPlugin.js +0 -34
  52. package/dist/struct/CustomPlugin.js.map +1 -1
  53. package/dist/struct/ExtractorPlugin.d.ts +0 -32
  54. package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
  55. package/dist/struct/ExtractorPlugin.js +0 -23
  56. package/dist/struct/ExtractorPlugin.js.map +1 -1
  57. package/dist/struct/Playlist.d.ts +0 -29
  58. package/dist/struct/Playlist.d.ts.map +1 -1
  59. package/dist/struct/Playlist.js +0 -54
  60. package/dist/struct/Playlist.js.map +1 -1
  61. package/dist/struct/Plugin.d.ts +0 -58
  62. package/dist/struct/Plugin.d.ts.map +1 -1
  63. package/dist/struct/Plugin.js +0 -62
  64. package/dist/struct/Plugin.js.map +1 -1
  65. package/dist/struct/Queue.d.ts +10 -177
  66. package/dist/struct/Queue.d.ts.map +1 -1
  67. package/dist/struct/Queue.js +49 -256
  68. package/dist/struct/Queue.js.map +1 -1
  69. package/dist/struct/SearchResult.d.ts +0 -8
  70. package/dist/struct/SearchResult.d.ts.map +1 -1
  71. package/dist/struct/SearchResult.js +0 -47
  72. package/dist/struct/SearchResult.js.map +1 -1
  73. package/dist/struct/Song.d.ts +0 -35
  74. package/dist/struct/Song.d.ts.map +1 -1
  75. package/dist/struct/Song.js +0 -121
  76. package/dist/struct/Song.js.map +1 -1
  77. package/dist/struct/TaskQueue.d.ts +0 -20
  78. package/dist/struct/TaskQueue.d.ts.map +1 -1
  79. package/dist/struct/TaskQueue.js +0 -25
  80. package/dist/struct/TaskQueue.js.map +1 -1
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/dist/type.d.ts +6 -71
  83. package/dist/type.d.ts.map +1 -1
  84. package/dist/type.js.map +1 -1
  85. package/dist/util.d.ts +0 -29
  86. package/dist/util.d.ts.map +1 -1
  87. package/dist/util.js +2 -38
  88. package/dist/util.js.map +1 -1
  89. package/package.json +13 -4
package/dist/DisTube.js CHANGED
@@ -9,124 +9,31 @@ const ytsr_1 = __importDefault(require("@distube/ytsr"));
9
9
  const util_1 = require("./util");
10
10
  const tiny_typed_emitter_1 = require("tiny-typed-emitter");
11
11
  const _1 = require(".");
12
- // Cannot be `import` as it's not under TS root dir
13
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
14
12
  exports.version = require("../package.json").version;
15
- /**
16
- * DisTube class
17
- * @extends EventEmitter
18
- */
19
13
  class DisTube extends tiny_typed_emitter_1.TypedEmitter {
20
- /**
21
- * Create a new DisTube class.
22
- * @param {Discord.Client} client Discord.JS client
23
- * @param {DisTubeOptions} [otp] Custom DisTube options
24
- * @example
25
- * const Discord = require('discord.js'),
26
- * DisTube = require('distube'),
27
- * client = new Discord.Client();
28
- * // Create a new DisTube
29
- * const distube = new DisTube.default(client, { searchSongs: 10 });
30
- * // client.DisTube = distube // make it access easily
31
- * client.login("Your Discord Bot Token")
32
- */
33
14
  constructor(client, otp = {}) {
34
15
  super();
35
16
  this.setMaxListeners(1);
36
17
  if (!(0, _1.isClientInstance)(client))
37
18
  throw new _1.DisTubeError("INVALID_TYPE", "Discord.Client", client, "client");
38
- /**
39
- * Discord.JS client
40
- * @type {Discord.Client}
41
- */
42
19
  this.client = client;
43
20
  (0, util_1.checkIntents)(client.options);
44
- /**
45
- * DisTube options
46
- * @type {DisTubeOptions}
47
- */
48
21
  this.options = new _1.Options(otp);
49
- /**
50
- * Voice connections manager
51
- * @type {DisTubeVoiceManager}
52
- */
53
22
  this.voices = new _1.DisTubeVoiceManager(this);
54
- /**
55
- * DisTube's Handler
56
- * @type {DisTubeHandler}
57
- * @private
58
- */
59
23
  this.handler = new _1.DisTubeHandler(this);
60
- /**
61
- * Queues manager
62
- * @type {QueueManager}
63
- */
64
24
  this.queues = new _1.QueueManager(this);
65
- /**
66
- * DisTube filters
67
- * @type {Filters}
68
- */
69
25
  this.filters = { ..._1.defaultFilters, ...this.options.customFilters };
70
- // Default plugin
71
26
  this.options.plugins.push(new _1.HTTPPlugin(), new _1.HTTPSPlugin());
72
27
  this.options.plugins.map(p => p.init(this));
73
- /**
74
- * Extractor Plugins
75
- * @type {ExtractorPlugin[]}
76
- * @private
77
- */
78
28
  this.extractorPlugins = this.options.plugins.filter((p) => p.type === "extractor");
79
- /**
80
- * Custom Plugins
81
- * @type {CustomPlugin[]}
82
- * @private
83
- */
84
29
  this.customPlugins = this.options.plugins.filter((p) => p.type === "custom");
85
30
  }
86
31
  static get version() {
87
32
  return exports.version;
88
33
  }
89
- /**
90
- * DisTube version
91
- * @type {string}
92
- */
93
34
  get version() {
94
35
  return exports.version;
95
36
  }
96
- /**
97
- * Play / add a song or playlist from url. Search and play a song if it is not a valid url.
98
- *
99
- * @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
100
- * @param {string|Song|SearchResult|Playlist} song URL | Search string |
101
- * {@link Song} | {@link SearchResult} | {@link Playlist}
102
- * @param {Object} [options] Optional options
103
- * @param {boolean} [options.skip=false]
104
- * Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
105
- * If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
106
- * @param {number} [options.position=0] Position of the song/playlist to add to the queue,
107
- * <= 0 to add to the end of the queue.
108
- * @param {boolean} [options.unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
109
- * (after the playing song if exists)
110
- * @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
111
- * @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
112
- * @param {Discord.Message} [options.message] Called message (For built-in search events. If this is a {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy|falsy value}, it will play the first result instead)
113
- * @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
114
- * This is useful for identification purposes when the song/playlist is passed around in events.
115
- * See {@link Song#metadata} or {@link Playlist#metadata}
116
- * @example
117
- * client.on('message', (message) => {
118
- * if (!message.content.startsWith(config.prefix)) return;
119
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
120
- * const command = args.shift();
121
- * if (command == "play")
122
- * distube.play(message.member.voice?.channel, args.join(" "), {
123
- * member: message.member,
124
- * textChannel: message.channel,
125
- * message
126
- * });
127
- * });
128
- * @returns {Promise<void>}
129
- */
130
37
  async play(voiceChannel, song, options = {}) {
131
38
  if (!(0, _1.isSupportedVoiceChannel)(voiceChannel)) {
132
39
  throw new _1.DisTubeError("INVALID_TYPE", "BaseGuildVoiceChannel", voiceChannel, "voiceChannel");
@@ -164,9 +71,9 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
164
71
  }
165
72
  }
166
73
  let queue = this.getQueue(voiceChannel);
167
- const queuing = !!queue && !queue.taskQueue.hasResolveTask;
74
+ const queuing = !!queue && !queue._taskQueue.hasResolveTask;
168
75
  if (queuing)
169
- await queue?.taskQueue.queuing(true);
76
+ await queue?._taskQueue.queuing(true);
170
77
  try {
171
78
  if (song instanceof _1.SearchResult && song.type === "playlist")
172
79
  song = song.url;
@@ -212,7 +119,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
212
119
  }
213
120
  finally {
214
121
  if (queuing)
215
- queue?.taskQueue.resolve();
122
+ queue?._taskQueue.resolve();
216
123
  }
217
124
  }
218
125
  catch (e) {
@@ -226,24 +133,6 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
226
133
  this.emitError(e, textChannel);
227
134
  }
228
135
  }
229
- /**
230
- * Create a custom playlist
231
- * @returns {Promise<Playlist>}
232
- * @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
233
- * @param {Object} [options] Optional options
234
- * @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
235
- * @param {Object} [options.properties] Additional properties such as `name`
236
- * @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
237
- * @param {*} [options.metadata] Metadata
238
- * @example
239
- * const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
240
- * const playlist = await distube.createCustomPlaylist(songs, {
241
- * member: message.member,
242
- * properties: { name: "My playlist name" },
243
- * parallel: true
244
- * });
245
- * distube.play(voiceChannel, playlist, { ... });
246
- */
247
136
  async createCustomPlaylist(songs, options = {}) {
248
137
  const { member, properties, parallel, metadata } = { parallel: true, ...options };
249
138
  if (!Array.isArray(songs))
@@ -272,18 +161,6 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
272
161
  }
273
162
  return new _1.Playlist(resolvedSongs, { member, properties, metadata });
274
163
  }
275
- /**
276
- * Search for a song. You can customize how user answers instead of send a number.
277
- * Then use {@link DisTube#play} to play it.
278
- *
279
- * @param {string} string The string search for
280
- * @param {Object} options Search options
281
- * @param {number} [options.limit=10] Limit the results
282
- * @param {'video'|'playlist'} [options.type='video'] Type of results (`video` or `playlist`).
283
- * @param {boolean} [options.safeSearch=false] Whether or not use safe search (YouTube restricted mode)
284
- * @throws {Error}
285
- * @returns {Promise<Array<SearchResult>>} Array of results
286
- */
287
164
  async search(string, options = {}) {
288
165
  const opts = { type: "video", limit: 10, safeSearch: false, ...options };
289
166
  if (typeof opts.type !== "string" || !["video", "playlist"].includes(opts.type)) {
@@ -310,309 +187,84 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
310
187
  return this.search(string, options);
311
188
  }
312
189
  }
313
- /**
314
- * Get the guild queue
315
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
316
- * @returns {Queue?}
317
- * @throws {Error}
318
- * @example
319
- * client.on('message', (message) => {
320
- * if (!message.content.startsWith(config.prefix)) return;
321
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
322
- * const command = args.shift();
323
- * if (command == "queue") {
324
- * const queue = distube.getQueue(message);
325
- * message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
326
- * `**${id+1}**. [${song.name}](${song.url}) - \`${song.formattedDuration}\``
327
- * ).join("\n"));
328
- * }
329
- * });
330
- */
331
- getQueue(queue) {
332
- return this.queues.get(queue);
190
+ getQueue(guild) {
191
+ return this.queues.get(guild);
333
192
  }
334
- /**
335
- * Pause the guild stream
336
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
337
- * @returns {Queue} The guild queue
338
- * @throws {Error}
339
- */
340
- pause(queue) {
341
- const q = this.getQueue(queue);
193
+ pause(guild) {
194
+ const q = this.getQueue(guild);
342
195
  if (!q)
343
196
  throw new _1.DisTubeError("NO_QUEUE");
344
197
  return q.pause();
345
198
  }
346
- /**
347
- * Resume the guild stream
348
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
349
- * @returns {Queue} The guild queue
350
- * @throws {Error}
351
- */
352
- resume(queue) {
353
- const q = this.getQueue(queue);
199
+ resume(guild) {
200
+ const q = this.getQueue(guild);
354
201
  if (!q)
355
202
  throw new _1.DisTubeError("NO_QUEUE");
356
203
  return q.resume();
357
204
  }
358
- /**
359
- * Stop the guild stream
360
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
361
- * @returns {Promise<void>}
362
- * @throws {Error}
363
- * @example
364
- * client.on('message', (message) => {
365
- * if (!message.content.startsWith(config.prefix)) return;
366
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
367
- * const command = args.shift();
368
- * if (command == "stop") {
369
- * distube.stop(message);
370
- * message.channel.send("Stopped the queue!");
371
- * }
372
- * });
373
- */
374
- stop(queue) {
375
- const q = this.getQueue(queue);
205
+ stop(guild) {
206
+ const q = this.getQueue(guild);
376
207
  if (!q)
377
208
  throw new _1.DisTubeError("NO_QUEUE");
378
209
  return q.stop();
379
210
  }
380
- /**
381
- * Set the guild stream's volume
382
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
383
- * @param {number} percent The percentage of volume you want to set
384
- * @returns {Queue} The guild queue
385
- * @throws {Error}
386
- * @example
387
- * client.on('message', (message) => {
388
- * if (!message.content.startsWith(config.prefix)) return;
389
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
390
- * const command = args.shift();
391
- * if (command == "volume")
392
- * distube.setVolume(message, Number(args[0]));
393
- * });
394
- */
395
- setVolume(queue, percent) {
396
- const q = this.getQueue(queue);
211
+ setVolume(guild, percent) {
212
+ const q = this.getQueue(guild);
397
213
  if (!q)
398
214
  throw new _1.DisTubeError("NO_QUEUE");
399
215
  return q.setVolume(percent);
400
216
  }
401
- /**
402
- * Skip the playing song if there is a next song in the queue.
403
- * <info>If {@link Queue#autoplay} is `true` and there is no up next song,
404
- * DisTube will add and play a related song.</info>
405
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
406
- * @returns {Promise<Song>} The new Song will be played
407
- * @throws {Error}
408
- * @example
409
- * client.on('message', (message) => {
410
- * if (!message.content.startsWith(config.prefix)) return;
411
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
412
- * const command = args.shift();
413
- * if (command == "skip")
414
- * distube.skip(message);
415
- * });
416
- */
417
- skip(queue) {
418
- const q = this.getQueue(queue);
217
+ skip(guild) {
218
+ const q = this.getQueue(guild);
419
219
  if (!q)
420
220
  throw new _1.DisTubeError("NO_QUEUE");
421
221
  return q.skip();
422
222
  }
423
- /**
424
- * Play the previous song
425
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
426
- * @returns {Promise<Song>} The new Song will be played
427
- * @throws {Error}
428
- * @example
429
- * client.on('message', (message) => {
430
- * if (!message.content.startsWith(config.prefix)) return;
431
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
432
- * const command = args.shift();
433
- * if (command == "previous")
434
- * distube.previous(message);
435
- * });
436
- */
437
- previous(queue) {
438
- const q = this.getQueue(queue);
223
+ previous(guild) {
224
+ const q = this.getQueue(guild);
439
225
  if (!q)
440
226
  throw new _1.DisTubeError("NO_QUEUE");
441
227
  return q.previous();
442
228
  }
443
- /**
444
- * Shuffle the guild queue songs
445
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
446
- * @returns {Promise<Queue>} The guild queue
447
- * @example
448
- * client.on('message', (message) => {
449
- * if (!message.content.startsWith(config.prefix)) return;
450
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
451
- * const command = args.shift();
452
- * if (command == "shuffle")
453
- * distube.shuffle(message);
454
- * });
455
- */
456
- shuffle(queue) {
457
- const q = this.getQueue(queue);
229
+ shuffle(guild) {
230
+ const q = this.getQueue(guild);
458
231
  if (!q)
459
232
  throw new _1.DisTubeError("NO_QUEUE");
460
233
  return q.shuffle();
461
234
  }
462
- /**
463
- * Jump to the song number in the queue.
464
- * The next one is 1, 2,...
465
- * The previous one is -1, -2,...
466
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
467
- * @param {number} num The song number to play
468
- * @returns {Promise<Queue>} The guild queue
469
- * @throws {Error} if `num` is invalid number (0 < num < {@link Queue#songs}.length)
470
- * @example
471
- * client.on('message', (message) => {
472
- * if (!message.content.startsWith(config.prefix)) return;
473
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
474
- * const command = args.shift();
475
- * if (command == "jump")
476
- * distube.jump(message, parseInt(args[0]))
477
- * .catch(err => message.channel.send("Invalid song number."));
478
- * });
479
- */
480
- jump(queue, num) {
481
- const q = this.getQueue(queue);
235
+ jump(guild, num) {
236
+ const q = this.getQueue(guild);
482
237
  if (!q)
483
238
  throw new _1.DisTubeError("NO_QUEUE");
484
239
  return q.jump(num);
485
240
  }
486
- /**
487
- * Set the repeat mode of the guild queue.\
488
- * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`
489
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
490
- * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)
491
- * @returns {RepeatMode} The new repeat mode
492
- * @example
493
- * client.on('message', (message) => {
494
- * if (!message.content.startsWith(config.prefix)) return;
495
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
496
- * const command = args.shift();
497
- * if (command == "repeat") {
498
- * let mode = distube.setRepeatMode(message, parseInt(args[0]));
499
- * mode = mode ? mode == 2 ? "Repeat queue" : "Repeat song" : "Off";
500
- * message.channel.send("Set repeat mode to `" + mode + "`");
501
- * }
502
- * });
503
- * @example
504
- * const { RepeatMode } = require("distube");
505
- * let mode;
506
- * switch(distube.setRepeatMode(message, parseInt(args[0]))) {
507
- * case RepeatMode.DISABLED:
508
- * mode = "Off";
509
- * break;
510
- * case RepeatMode.SONG:
511
- * mode = "Repeat a song";
512
- * break;
513
- * case RepeatMode.QUEUE:
514
- * mode = "Repeat all queue";
515
- * break;
516
- * }
517
- * message.channel.send("Set repeat mode to `" + mode + "`");
518
- */
519
- setRepeatMode(queue, mode) {
520
- const q = this.getQueue(queue);
241
+ setRepeatMode(guild, mode) {
242
+ const q = this.getQueue(guild);
521
243
  if (!q)
522
244
  throw new _1.DisTubeError("NO_QUEUE");
523
245
  return q.setRepeatMode(mode);
524
246
  }
525
- /**
526
- * Toggle autoplay mode
527
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
528
- * @returns {boolean} Autoplay mode state
529
- * @throws {Error}
530
- * @example
531
- * client.on('message', (message) => {
532
- * if (!message.content.startsWith(config.prefix)) return;
533
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
534
- * const command = args.shift();
535
- * if (command == "autoplay") {
536
- * const mode = distube.toggleAutoplay(message);
537
- * message.channel.send("Set autoplay mode to `" + (mode ? "On" : "Off") + "`");
538
- * }
539
- * });
540
- */
541
- toggleAutoplay(queue) {
542
- const q = this.getQueue(queue);
247
+ toggleAutoplay(guild) {
248
+ const q = this.getQueue(guild);
543
249
  if (!q)
544
250
  throw new _1.DisTubeError("NO_QUEUE");
545
251
  q.autoplay = !q.autoplay;
546
252
  return q.autoplay;
547
253
  }
548
- /**
549
- * Add related song to the queue
550
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
551
- * @returns {Promise<Song>} The guild queue
552
- */
553
- addRelatedSong(queue) {
554
- const q = this.getQueue(queue);
254
+ addRelatedSong(guild) {
255
+ const q = this.getQueue(guild);
555
256
  if (!q)
556
257
  throw new _1.DisTubeError("NO_QUEUE");
557
258
  return q.addRelatedSong();
558
259
  }
559
- /**
560
- * Enable or disable filter(s) of the queue.
561
- * Available filters: {@link Filters}
562
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
563
- * @param {string|false} filter A filter name, `false` to clear all the filters
564
- * @param {boolean} [force=false] Force enable the input filter(s) even if it's enabled
565
- * @returns {Array<string>} Enabled filters.
566
- * @example
567
- * client.on('message', (message) => {
568
- * if (!message.content.startsWith(config.prefix)) return;
569
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
570
- * const command = args.shift();
571
- * if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
572
- * const filter = distube.setFilter(message, command);
573
- * message.channel.send("Current queue filter: " + (filter.join(", ") || "Off"));
574
- * }
575
- * });
576
- */
577
- setFilter(queue, filter, force = false) {
578
- const q = this.getQueue(queue);
579
- if (!q)
580
- throw new _1.DisTubeError("NO_QUEUE");
581
- return q.setFilter(filter, force);
582
- }
583
- /**
584
- * Set the playing time to another position
585
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
586
- * @param {number} time Time in seconds
587
- * @returns {Queue} Seeked queue
588
- * @example
589
- * client.on('message', message => {
590
- * if (!message.content.startsWith(config.prefix)) return;
591
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
592
- * const command = args.shift();
593
- * if (command = 'seek')
594
- * distube.seek(message, Number(args[0]));
595
- * });
596
- */
597
- seek(queue, time) {
598
- const q = this.getQueue(queue);
260
+ seek(guild, time) {
261
+ const q = this.getQueue(guild);
599
262
  if (!q)
600
263
  throw new _1.DisTubeError("NO_QUEUE");
601
264
  return q.seek(time);
602
265
  }
603
- /* eslint-disable no-console */
604
- /**
605
- * Emit error event
606
- * @param {Error} error error
607
- * @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
608
- * @private
609
- */
610
266
  emitError(error, channel) {
611
- if (!channel || !(0, _1.isTextChannelInstance)(channel)) {
612
- console.error(error);
613
- console.warn("This is logged because <Queue>.textChannel is undefined");
614
- }
615
- else if (this.listeners("error").length) {
267
+ if (this.listeners("error").length) {
616
268
  this.emit("error", channel, error);
617
269
  }
618
270
  else {
@@ -624,170 +276,4 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
624
276
  }
625
277
  exports.DisTube = DisTube;
626
278
  exports.default = DisTube;
627
- /**
628
- * Emitted after DisTube add a new playlist to the playing {@link Queue}.
629
- *
630
- * @event DisTube#addList
631
- * @param {Queue} queue The guild queue
632
- * @param {Playlist} playlist Playlist info
633
- * @example
634
- * distube.on("addList", (queue, playlist) => queue.textChannel.send(
635
- * `Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to the queue!`
636
- * ));
637
- */
638
- /**
639
- * Emitted after DisTube add a new song to the playing {@link Queue}.
640
- *
641
- * @event DisTube#addSong
642
- * @param {Queue} queue The guild queue
643
- * @param {Song} song Added song
644
- * @example
645
- * distube.on("addSong", (queue, song) => queue.textChannel.send(
646
- * `Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}.`
647
- * ));
648
- */
649
- /**
650
- * Emitted when there is no user in the voice channel,
651
- * {@link DisTubeOptions}.leaveOnEmpty is `true` and there is a playing queue.
652
- *
653
- * If there is no playing queue (stopped and {@link DisTubeOptions}.leaveOnStop is `false`),
654
- * it will leave the channel without emitting this event.
655
- * @event DisTube#empty
656
- * @param {Queue} queue The guild queue
657
- * @example
658
- * distube.on("empty", queue => queue.textChannel.send("Channel is empty. Leaving the channel"))
659
- */
660
- /**
661
- * Emitted when DisTube encounters an error.
662
- *
663
- * @event DisTube#error
664
- * @param {Discord.BaseGuildTextChannel} channel Text channel where the error is encountered.
665
- * @param {Error} error The error encountered
666
- * @example
667
- * distube.on("error", (channel, error) => channel.send(
668
- * "An error encountered: " + error
669
- * ));
670
- */
671
- /**
672
- * Emitted when there is no more song in the queue and {@link Queue#autoplay} is `false`.
673
- * DisTube will leave voice channel if {@link DisTubeOptions}.leaveOnFinish is `true`.
674
- *
675
- * @event DisTube#finish
676
- * @param {Queue} queue The guild queue
677
- * @example
678
- * distube.on("finish", queue => queue.textChannel.send("No more song in queue"));
679
- */
680
- /**
681
- * Emitted when DisTube initialize a queue to change queue default properties.
682
- *
683
- * @event DisTube#initQueue
684
- * @param {Queue} queue The guild queue
685
- * @example
686
- * distube.on("initQueue", queue => {
687
- * queue.autoplay = false;
688
- * queue.volume = 100;
689
- * });
690
- */
691
- /**
692
- * Emitted when {@link Queue#autoplay} is `true`, {@link Queue#songs} is empty,
693
- * and DisTube cannot find related songs to play.
694
- *
695
- * @event DisTube#noRelated
696
- * @param {Queue} queue The guild queue
697
- * @example
698
- * distube.on("noRelated", queue => queue.textChannel.send("Can't find related video to play."));
699
- */
700
- /**
701
- * Emitted when DisTube play a song.
702
- *
703
- * If {@link DisTubeOptions}.emitNewSongOnly is `true`,
704
- * this event is not emitted when looping a song or next song is the previous one.
705
- *
706
- * @event DisTube#playSong
707
- * @param {Queue} queue The guild queue
708
- * @param {Song} song Playing song
709
- * @example
710
- * distube.on("playSong", (queue, song) => queue.textChannel.send(
711
- * `Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}`
712
- * ));
713
- */
714
- /**
715
- * Emitted when DisTube cannot find any results for the query.
716
- *
717
- * @event DisTube#searchNoResult
718
- * @param {Discord.Message} message The user message called play method
719
- * @param {string} query The search query
720
- * @example
721
- * distube.on("searchNoResult", (message, query) => message.channel.send(`No result found for ${query}!`));
722
- */
723
- /**
724
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
725
- * and song param of {@link DisTube#play} is invalid url.
726
- * DisTube will wait for user's next message to choose a song manually.
727
- * <info>{@link https://support.google.com/youtube/answer/7354993|Safe search} is enabled
728
- * if {@link DisTubeOptions}.nsfw is disabled and the message's channel is not a nsfw channel.</info>
729
- *
730
- * @event DisTube#searchResult
731
- * @param {Discord.Message} message The user message called play method
732
- * @param {Array<SearchResult>} results Searched results
733
- * @param {string} query The search query
734
- * @example
735
- * // DisTubeOptions.searchSongs > 0
736
- * distube.on("searchResult", (message, results) => {
737
- * message.channel.send(`**Choose an option from below**\n${
738
- * results.map((song, i) => `**${i + 1}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")
739
- * }\n*Enter anything else or wait 60 seconds to cancel*`);
740
- * });
741
- */
742
- /**
743
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
744
- * and the search canceled due to {@link DisTubeOptions|DisTubeOptions.searchTimeout}.
745
- *
746
- * @event DisTube#searchCancel
747
- * @param {Discord.Message} message The user message called play method
748
- * @param {string} query The search query
749
- * @example
750
- * // DisTubeOptions.searchSongs > 0
751
- * distube.on("searchCancel", (message) => message.channel.send(`Searching canceled`));
752
- */
753
- /**
754
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
755
- * and the search canceled due to user's next message is not a number or out of results range.
756
- *
757
- * @event DisTube#searchInvalidAnswer
758
- * @param {Discord.Message} message The user message called play method
759
- * @param {Discord.Message} answer The answered message of user
760
- * @param {string} query The search query
761
- * @example
762
- * // DisTubeOptions.searchSongs > 0
763
- * distube.on("searchInvalidAnswer", (message) => message.channel.send(`You answered an invalid number!`));
764
- */
765
- /**
766
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
767
- * and after the user chose a search result to play.
768
- *
769
- * @event DisTube#searchDone
770
- * @param {Discord.Message} message The user message called play method
771
- * @param {Discord.Message} answer The answered message of user
772
- * @param {string} query The search query
773
- */
774
- /**
775
- * Emitted when the bot is disconnected to a voice channel.
776
- *
777
- * @event DisTube#disconnect
778
- * @param {Queue} queue The guild queue
779
- */
780
- /**
781
- * Emitted when a {@link Queue} is deleted with any reasons.
782
- *
783
- * @event DisTube#deleteQueue
784
- * @param {Queue} queue The guild queue
785
- */
786
- /**
787
- * Emitted when DisTube finished a song.
788
- *
789
- * @event DisTube#finishSong
790
- * @param {Queue} queue The guild queue
791
- * @param {Song} song Finished song
792
- */
793
279
  //# sourceMappingURL=DisTube.js.map