distube 4.0.3 → 4.0.5

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  <a href="https://www.npmjs.com/package/distube" target="_blank"><img src="https://nodei.co/npm/distube.png?downloads=true&downloadRank=true&stars=true"></a>
4
4
  </p>
5
5
  <p>
6
- <a href="https://github.com/skick1234/DisTube/actions" target="_blank"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/skick1234/DisTube/Testing?label=Tests&logo=github&style=flat-square"></a>
6
+ <a href="https://github.com/skick1234/DisTube/actions" target="_blank"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/skick1234/DisTube/test.yml?branch=main&label=Tests&logo=github&style=flat-square"></a>
7
7
  <a href="https://nodejs.org/" target="_blank"><img alt="node-current" src="https://img.shields.io/node/v/distube?logo=node.js&logoColor=white&style=flat-square"></a>
8
8
  <a href="https://discord.js.org/" target="_blank"><img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/distube/peer/discord.js?label=discord.js&logo=discord&logoColor=white&style=flat-square"></a>
9
9
  <a href="https://depfu.com/github/skick1234/DisTube?project_id=36112" target="_blank"><img alt="Depfu" src="https://img.shields.io/depfu/dependencies/github/skick1234/DisTube?style=flat-square"></a>
@@ -42,21 +42,16 @@ A Discord.js module to simplify your music commands and play songs with audio fi
42
42
  ## Installation
43
43
 
44
44
  ```npm
45
- npm install distube@dev
45
+ npm install distube@latest
46
46
  ```
47
47
 
48
48
  ## Documentation
49
49
 
50
50
  Read DisTube's definitions, properties and events details in the [Documentation page](https://distube.js.org/).
51
51
 
52
+ Learn how to build a music bot from scratch with [DisTube Guide](https://distube.js.org/guide)
53
+
52
54
  ## Example Bot
53
55
 
54
56
  - [DisTube Bot](https://skick.xyz/DisTube) - A music bot with reaction controller, filters, DJ mode, user's custom playlist and voting.
55
57
  - [DisTube Example](https://github.com/distubejs/example) - Example bot with simple command handler.
56
- - [DisTube Guide](https://distube.js.org/guide) - How to build a music bot from scratch.
57
-
58
- ## Dependencies
59
-
60
- - [node-ytdl-core](https://github.com/fent/node-ytdl-core): YouTube scraper ([DisTube Fork](https://github.com/distubejs/node-ytdl-core))
61
- - [node-ytsr](https://github.com/TimeForANinja/node-ytsr): YouTube search scraper ([DisTube Fork](https://github.com/distubejs/ytsr))
62
- - [node-ytpl](https://github.com/TimeForANinja/node-ytpl): YouTube playlist resolver ([DisTube Fork](https://github.com/distubejs/ytpl))
package/dist/index.d.ts CHANGED
@@ -1,37 +1,20 @@
1
1
  import ytdl from '@distube/ytdl-core';
2
2
  import * as discord_js from 'discord.js';
3
3
  import { GuildTextBasedChannel, Message, Snowflake, VoiceBasedChannel, VoiceState, Guild, GuildMember, Interaction, Client, Collection, ClientOptions } from 'discord.js';
4
+ import ytpl from '@distube/ytpl';
4
5
  import { Video, Playlist as Playlist$1 } from '@distube/ytsr';
5
6
  import { TypedEmitter } from 'tiny-typed-emitter';
6
7
  import { AudioPlayer, VoiceConnection, AudioResource, StreamType as StreamType$1 } from '@discordjs/voice';
7
8
  import { FFmpeg } from 'prism-media';
8
9
  import * as _discordjs_collection from '@discordjs/collection';
9
10
 
10
- declare type Awaitable<T = any> = T | PromiseLike<T>;
11
- declare type DisTubeVoiceEvents = {
11
+ type Awaitable<T = any> = T | PromiseLike<T>;
12
+ type DisTubeVoiceEvents = {
12
13
  disconnect: (error?: Error) => Awaitable;
13
14
  error: (error: Error) => Awaitable;
14
15
  finish: () => Awaitable;
15
16
  };
16
- declare enum Events {
17
- ERROR = "error",
18
- ADD_LIST = "addList",
19
- ADD_SONG = "addSong",
20
- PLAY_SONG = "playSong",
21
- FINISH_SONG = "finishSong",
22
- EMPTY = "empty",
23
- FINISH = "finish",
24
- INIT_QUEUE = "initQueue",
25
- NO_RELATED = "noRelated",
26
- DISCONNECT = "disconnect",
27
- DELETE_QUEUE = "deleteQueue",
28
- SEARCH_CANCEL = "searchCancel",
29
- SEARCH_NO_RESULT = "searchNoResult",
30
- SEARCH_DONE = "searchDone",
31
- SEARCH_INVALID_ANSWER = "searchInvalidAnswer",
32
- SEARCH_RESULT = "searchResult"
33
- }
34
- declare type DisTubeEvents = {
17
+ type DisTubeEvents = {
35
18
  error: [channel: GuildTextBasedChannel | undefined, error: Error];
36
19
  addList: [queue: Queue, playlist: Playlist];
37
20
  addSong: [queue: Queue, song: Song];
@@ -49,15 +32,15 @@ declare type DisTubeEvents = {
49
32
  searchInvalidAnswer: [message: Message<true>, answer: Message<true>, query: string];
50
33
  searchResult: [message: Message<true>, results: SearchResult[], query: string];
51
34
  };
52
- declare type TypedDisTubeEvents = {
35
+ type TypedDisTubeEvents = {
53
36
  [K in keyof DisTubeEvents]: (...args: DisTubeEvents[K]) => Awaitable;
54
37
  };
55
38
  interface Filter {
56
39
  name: string;
57
40
  value: string;
58
41
  }
59
- declare type FilterResolvable = string | Filter;
60
- declare type Filters = Record<string, string>;
42
+ type FilterResolvable = string | Filter;
43
+ type Filters = Record<string, string>;
61
44
  interface DisTubeOptions {
62
45
  plugins?: (CustomPlugin | ExtractorPlugin)[];
63
46
  emitNewSongOnly?: boolean;
@@ -79,9 +62,9 @@ interface DisTubeOptions {
79
62
  streamType?: StreamType;
80
63
  directLink?: boolean;
81
64
  }
82
- declare type GuildIdResolvable = Queue | DisTubeVoice | Snowflake | Message | GuildTextBasedChannel | VoiceBasedChannel | VoiceState | Guild | GuildMember | Interaction | string;
65
+ type GuildIdResolvable = Queue | DisTubeVoice | Snowflake | Message | GuildTextBasedChannel | VoiceBasedChannel | VoiceState | Guild | GuildMember | Interaction | string;
83
66
  interface OtherSongInfo {
84
- src?: string;
67
+ src: string;
85
68
  id?: string;
86
69
  title?: string;
87
70
  name?: string;
@@ -124,8 +107,8 @@ interface PlaylistInfo {
124
107
  title?: string;
125
108
  webpage_url?: string;
126
109
  }
127
- declare type RelatedSong = Omit<Song, "related">;
128
- declare type PlayHandlerOptions = {
110
+ type RelatedSong = Omit<Song, "related">;
111
+ type PlayHandlerOptions = {
129
112
  skip?: boolean;
130
113
  position?: number;
131
114
  textChannel?: GuildTextBasedChannel;
@@ -163,6 +146,24 @@ declare enum StreamType {
163
146
  OPUS = 0,
164
147
  RAW = 1
165
148
  }
149
+ declare enum Events {
150
+ ERROR = "error",
151
+ ADD_LIST = "addList",
152
+ ADD_SONG = "addSong",
153
+ PLAY_SONG = "playSong",
154
+ FINISH_SONG = "finishSong",
155
+ EMPTY = "empty",
156
+ FINISH = "finish",
157
+ INIT_QUEUE = "initQueue",
158
+ NO_RELATED = "noRelated",
159
+ DISCONNECT = "disconnect",
160
+ DELETE_QUEUE = "deleteQueue",
161
+ SEARCH_CANCEL = "searchCancel",
162
+ SEARCH_NO_RESULT = "searchNoResult",
163
+ SEARCH_DONE = "searchDone",
164
+ SEARCH_INVALID_ANSWER = "searchInvalidAnswer",
165
+ SEARCH_RESULT = "searchResult"
166
+ }
166
167
 
167
168
  declare const defaultFilters: Filters;
168
169
  declare const defaultOptions: {
@@ -223,12 +224,12 @@ declare const ERROR_MESSAGES: {
223
224
  EMPTY_FILTERED_PLAYLIST: string;
224
225
  EMPTY_PLAYLIST: string;
225
226
  };
226
- declare type ErrorMessage = typeof ERROR_MESSAGES;
227
- declare type ErrorCode = keyof ErrorMessage;
228
- declare type StaticErrorCode = {
227
+ type ErrorMessage = typeof ERROR_MESSAGES;
228
+ type ErrorCode = keyof ErrorMessage;
229
+ type StaticErrorCode = {
229
230
  [K in ErrorCode]-?: ErrorMessage[K] extends string ? K : never;
230
231
  }[ErrorCode];
231
- declare type TemplateErrorCode = Exclude<keyof typeof ERROR_MESSAGES, StaticErrorCode>;
232
+ type TemplateErrorCode = Exclude<keyof typeof ERROR_MESSAGES, StaticErrorCode>;
232
233
  declare class DisTubeError<T extends string> extends Error {
233
234
  errorCode: string;
234
235
  constructor(code: StaticErrorCode);
@@ -290,7 +291,7 @@ declare class SearchResultVideo extends ISearchResult {
290
291
  thumbnail: string;
291
292
  constructor(info: Video);
292
293
  }
293
- declare type SearchResult = SearchResultVideo | SearchResultPlaylist;
294
+ type SearchResult = SearchResultVideo | SearchResultPlaylist;
294
295
  declare class SearchResultPlaylist extends ISearchResult {
295
296
  type: SearchResultType.PLAYLIST;
296
297
  length: number;
@@ -320,7 +321,7 @@ declare class Song<T = unknown> {
320
321
  age_restricted: boolean;
321
322
  chapters: Chapter[];
322
323
  reposts: number;
323
- constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong, options?: {
324
+ constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong | ytpl.result["items"][number], options?: {
324
325
  member?: GuildMember;
325
326
  source?: string;
326
327
  metadata?: T;
@@ -377,43 +378,20 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
377
378
  get voiceState(): VoiceState | undefined;
378
379
  }
379
380
 
380
- declare abstract class BaseManager<V> extends DisTubeBase {
381
- collection: Collection<string, V>;
382
- get size(): number;
383
- }
384
-
385
- declare abstract class GuildIdManager<V> extends BaseManager<V> {
386
- add(idOrInstance: GuildIdResolvable, data: V): this | _discordjs_collection.Collection<string, V>;
387
- get(idOrInstance: GuildIdResolvable): V | undefined;
388
- remove(idOrInstance: GuildIdResolvable): boolean;
389
- has(idOrInstance: GuildIdResolvable): boolean;
390
- }
391
-
392
- declare class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {
393
- create(channel: VoiceBasedChannel): DisTubeVoice;
394
- join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
395
- leave(guild: GuildIdResolvable): void;
396
- }
397
-
398
- declare class FilterManager extends BaseManager<FilterResolvable> {
399
- #private;
400
- queue: Queue;
401
- constructor(queue: Queue);
402
- add(filterOrFilters: FilterResolvable | FilterResolvable[], override?: boolean): this;
403
- clear(): this;
404
- set(filters: FilterResolvable[]): this;
405
- remove(filterOrFilters: FilterResolvable | FilterResolvable[]): this;
406
- has(filter: FilterResolvable): boolean;
407
- get names(): string[];
408
- get values(): string[];
409
- toString(): string;
381
+ interface StreamOptions {
382
+ seek?: number;
383
+ ffmpegArgs?: string[];
384
+ isLive?: boolean;
385
+ type?: StreamType;
410
386
  }
411
-
412
- declare class QueueManager extends GuildIdManager<Queue> {
413
- #private;
414
- create(channel: VoiceBasedChannel, song: Song[] | Song, textChannel?: GuildTextBasedChannel): Promise<Queue | true>;
415
- createStream(queue: Queue): DisTubeStream;
416
- playSong(queue: Queue): Promise<boolean>;
387
+ declare const chooseBestVideoFormat: (formats: ytdl.videoFormat[], isLive?: boolean) => ytdl.videoFormat;
388
+ declare class DisTubeStream {
389
+ static YouTube(formats: ytdl.videoFormat[] | undefined, options?: StreamOptions): DisTubeStream;
390
+ static DirectLink(url: string, options?: StreamOptions): DisTubeStream;
391
+ type: StreamType$1;
392
+ stream: FFmpeg;
393
+ url: string;
394
+ constructor(url: string, options: StreamOptions);
417
395
  }
418
396
 
419
397
  declare class DisTubeHandler extends DisTubeBase {
@@ -433,6 +411,7 @@ declare class DisTubeHandler extends DisTubeBase {
433
411
  createSearchMessageCollector<R extends SearchResult | Song | Playlist>(message: Message<true>, results: Array<R>, query?: string): Promise<R | null>;
434
412
  playPlaylist(voiceChannel: VoiceBasedChannel, playlist: Playlist, options?: PlayHandlerOptions): Promise<void>;
435
413
  playSong(voiceChannel: VoiceBasedChannel, song: Song, options?: PlayHandlerOptions): Promise<void>;
414
+ attachStreamInfo(song: Song): Promise<void>;
436
415
  }
437
416
 
438
417
  declare class Options {
@@ -459,20 +438,43 @@ declare class Options {
459
438
  constructor(options: DisTubeOptions);
460
439
  }
461
440
 
462
- interface StreamOptions {
463
- seek?: number;
464
- ffmpegArgs?: string[];
465
- isLive?: boolean;
466
- type?: StreamType;
441
+ declare abstract class BaseManager<V> extends DisTubeBase {
442
+ collection: Collection<string, V>;
443
+ get size(): number;
467
444
  }
468
- declare const chooseBestVideoFormat: (formats: ytdl.videoFormat[], isLive?: boolean) => ytdl.videoFormat;
469
- declare class DisTubeStream {
470
- static YouTube(formats: ytdl.videoFormat[] | undefined, options?: StreamOptions): DisTubeStream;
471
- static DirectLink(url: string, options?: StreamOptions): DisTubeStream;
472
- type: StreamType$1;
473
- stream: FFmpeg;
474
- url: string;
475
- constructor(url: string, options: StreamOptions);
445
+
446
+ declare abstract class GuildIdManager<V> extends BaseManager<V> {
447
+ add(idOrInstance: GuildIdResolvable, data: V): this | _discordjs_collection.Collection<string, V>;
448
+ get(idOrInstance: GuildIdResolvable): V | undefined;
449
+ remove(idOrInstance: GuildIdResolvable): boolean;
450
+ has(idOrInstance: GuildIdResolvable): boolean;
451
+ }
452
+
453
+ declare class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {
454
+ create(channel: VoiceBasedChannel): DisTubeVoice;
455
+ join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
456
+ leave(guild: GuildIdResolvable): void;
457
+ }
458
+
459
+ declare class FilterManager extends BaseManager<FilterResolvable> {
460
+ #private;
461
+ queue: Queue;
462
+ constructor(queue: Queue);
463
+ add(filterOrFilters: FilterResolvable | FilterResolvable[], override?: boolean): this;
464
+ clear(): this;
465
+ set(filters: FilterResolvable[]): this;
466
+ remove(filterOrFilters: FilterResolvable | FilterResolvable[]): this;
467
+ has(filter: FilterResolvable): boolean;
468
+ get names(): string[];
469
+ get values(): string[];
470
+ toString(): string;
471
+ }
472
+
473
+ declare class QueueManager extends GuildIdManager<Queue> {
474
+ #private;
475
+ create(channel: VoiceBasedChannel, song: Song[] | Song, textChannel?: GuildTextBasedChannel): Promise<Queue | true>;
476
+ createStream(queue: Queue): DisTubeStream;
477
+ playSong(queue: Queue): Promise<boolean>;
476
478
  }
477
479
 
478
480
  declare class Queue extends DisTubeBase {
@@ -551,7 +553,8 @@ declare abstract class ExtractorPlugin extends Plugin {
551
553
  declare function formatDuration(sec: number): string;
552
554
  declare function toSecond(input: any): number;
553
555
  declare function parseNumber(input: any): number;
554
- declare function isURL(input: any): input is `http://${string}` | `https://${string}`;
556
+ declare const SUPPORTED_PROTOCOL: readonly ["https:", "http:", "file:"];
557
+ declare function isURL(input: any): input is `${(typeof SUPPORTED_PROTOCOL)[number]}//${string}`;
555
558
  declare function checkIntents(options: ClientOptions): void;
556
559
  declare function isVoiceChannelEmpty(voiceState: VoiceState): boolean;
557
560
  declare function isSnowflake(id: any): id is Snowflake;
@@ -565,8 +568,9 @@ declare function isClientInstance(client: any): client is Client;
565
568
  declare function checkInvalidKey(target: Record<string, any>, source: Record<string, any> | string[], sourceName: string): void;
566
569
  declare function isObject(obj: any): obj is object;
567
570
  declare function isRecord<T = unknown>(obj: any): obj is Record<string, T>;
568
- declare type KeyOf<T> = T extends object ? (keyof T)[] : [];
571
+ type KeyOf<T> = T extends object ? (keyof T)[] : [];
569
572
  declare function objectKeys<T>(obj: T): KeyOf<T>;
573
+ declare function isNsfwChannel(channel?: GuildTextBasedChannel): boolean;
570
574
 
571
575
  declare class DirectLinkPlugin extends ExtractorPlugin {
572
576
  validate(url: string): Promise<boolean>;
@@ -591,12 +595,6 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
591
595
  get version(): string;
592
596
  play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist, options?: PlayOptions): Promise<void>;
593
597
  createCustomPlaylist(songs: (string | Song | SearchResult)[], options?: CustomPlaylistOptions): Promise<Playlist>;
594
- search(string: string, options?: {
595
- type?: SearchResultType;
596
- limit?: number;
597
- safeSearch?: boolean;
598
- retried?: boolean;
599
- }): Promise<Array<SearchResult>>;
600
598
  search(string: string, options?: {
601
599
  type?: SearchResultType.VIDEO;
602
600
  limit?: number;
@@ -609,6 +607,12 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
609
607
  safeSearch?: boolean;
610
608
  retried?: boolean;
611
609
  }): Promise<Array<SearchResultPlaylist>>;
610
+ search(string: string, options?: {
611
+ type?: SearchResultType;
612
+ limit?: number;
613
+ safeSearch?: boolean;
614
+ retried?: boolean;
615
+ }): Promise<Array<SearchResult>>;
612
616
  getQueue(guild: GuildIdResolvable): Queue | undefined;
613
617
  pause(guild: GuildIdResolvable): Queue;
614
618
  resume(guild: GuildIdResolvable): Queue;
@@ -625,4 +629,4 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
625
629
  emitError(error: Error, channel?: GuildTextBasedChannel): void;
626
630
  }
627
631
 
628
- export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DirectLinkPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, Events, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, TypedDisTubeEvents, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isURL, isVoiceChannelEmpty, objectKeys, parseNumber, resolveGuildId, toSecond, version };
632
+ export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DirectLinkPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, Events, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, TypedDisTubeEvents, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isNsfwChannel, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isURL, isVoiceChannelEmpty, objectKeys, parseNumber, resolveGuildId, toSecond, version };