lavalink-client 2.9.0 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -417,7 +417,19 @@ declare function parseLavalinkConnUrl(connectionUrl: string): {
417
417
  declare class ManagerUtils {
418
418
  LavalinkManager: LavalinkManager | undefined;
419
419
  constructor(LavalinkManager?: LavalinkManager);
420
+ /**
421
+ * Builds a pluginInfo object based on the provided data, extracting relevant information from the data and clientData parameters. This function is used to construct the pluginInfo property for tracks, allowing for consistent handling of plugin-related information across different track sources and formats.
422
+ * @param data
423
+ * @param clientData
424
+ * @returns
425
+ */
420
426
  buildPluginInfo(data: any, clientData?: any): any;
427
+ /**
428
+ * Builds a Track object from the provided data and requester information. It validates the presence of required properties in the data, transforms the requester using a custom transformer function if provided, and constructs a Track object with the appropriate properties and plugin information. The function also includes error handling to ensure that the input data is valid and provides debug information if track building fails.
429
+ * @param data
430
+ * @param requester
431
+ * @returns
432
+ */
421
433
  buildTrack(data: LavalinkTrack | Track, requester: unknown): Track;
422
434
  /**
423
435
  * Builds a UnresolvedTrack to be resolved before being played .
@@ -430,6 +442,11 @@ declare class ManagerUtils {
430
442
  * @param data
431
443
  */
432
444
  isNode(data: LavalinkNode): boolean;
445
+ /**
446
+ * Gets the transformed requester based on the LavalinkManager options. If a custom requester transformer function is provided in the player options, it applies that function to the requester; otherwise, it returns the requester as is. The function also includes error handling to catch any exceptions that may occur during the transformation process and emits a debug event if the transformation fails.
447
+ * @param requester
448
+ * @returns
449
+ */
433
450
  getTransformedRequester(requester: unknown): unknown;
434
451
  /**
435
452
  * Validate if a data is equal to node options
@@ -470,18 +487,73 @@ declare class ManagerUtils {
470
487
  * @param track
471
488
  */
472
489
  isUnresolvedTrackQuery(data: UnresolvedQuery): boolean;
490
+ /**
491
+ * Gets the closest track by resolving the provided UnresolvedTrack using the getClosestTrack function. It includes error handling to catch any exceptions that may occur during the resolution process and emits a debug event if the resolution fails. The function returns a Promise that resolves to a Track object if successful, or undefined if no closest track is found.
492
+ * @param data
493
+ * @param player
494
+ * @returns
495
+ */
473
496
  getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
474
- validateQueryString(node: LavalinkNode, queryString: string, sourceString?: LavalinkSearchPlatform): void;
497
+ /**
498
+ * Validates the query string against various criteria, including checking for empty strings, length limits for specific sources, blacklisted links or words, and ensuring that the Lavalink node has the necessary source managers enabled for the provided query. The function also includes debug event emissions to assist with troubleshooting and understanding the validation process.
499
+ * @param node
500
+ * @param queryString
501
+ * @param sourceString
502
+ * @returns
503
+ */
504
+ validateQueryString(node: LavalinkNode, queryString: string, sourceString?: SearchPlatform): void;
505
+ /**
506
+ * Finds the source of a query string by checking if it starts with a valid source prefix defined in the DefaultSources object. If a valid source prefix is found, it returns the corresponding SearchPlatform; otherwise, it returns null. This function is useful for determining the intended search platform for a given query string, allowing for more accurate search results when the user specifies a source (e.g., "ytsearch:Never Gonna Give You Up" would indicate that the search should be performed on YouTube).
507
+ * @param queryString
508
+ * @returns
509
+ */
510
+ findSourceOfQuery(queryString: string): SearchPlatform;
511
+ /**
512
+ * Extracts the source from the query if it starts with a valid source prefix (e.g., "ytsearch:") and updates the searchQuery object accordingly.
513
+ * @param searchQuery
514
+ * @returns The updated searchQuery object with the extracted source and modified query string.
515
+ */
516
+ extractSourceOfQuery<T extends {
517
+ query: string;
518
+ source?: string;
519
+ }>(searchQuery: T): T;
520
+ /**
521
+ * Converts a string to lowercase if the input is a string, otherwise returns the input as is. This is useful for ensuring that search platform identifiers are case-insensitive while allowing other types of input to pass through unchanged.
522
+ * @param input
523
+ * @returns
524
+ */
525
+ typedLowerCase<T extends unknown>(input: T): T;
526
+ /**
527
+ * Transforms a search query by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, and the determined search platform to be used for the search operation.
528
+ * @param query
529
+ * @returns
530
+ */
475
531
  transformQuery(query: SearchQuery): {
476
532
  query: string;
477
- extraQueryUrlParams: URLSearchParams;
478
- source: any;
533
+ extraQueryUrlParams: any;
534
+ source: SearchPlatform;
479
535
  };
536
+ /**
537
+ * Transforms a LavaSearchQuery by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, the determined search platform to be used for the search operation, and the types of search (track, playlist, artist, album, text) to be performed.
538
+ * @param query
539
+ * @returns
540
+ */
480
541
  transformLavaSearchQuery(query: LavaSearchQuery): {
542
+ query: never;
543
+ types: any[];
544
+ extraQueryUrlParams: any;
545
+ source: SearchPlatform;
546
+ } | {
481
547
  query: string;
482
548
  types: string[];
483
- source: any;
549
+ source: "ytsearch" | "ytmsearch" | "scsearch" | "bcsearch" | "spsearch" | "sprec" | "amsearch" | "dzsearch" | "dzisrc" | "dzrec" | "ymsearch" | "ymrec" | "vksearch" | "vkrec" | "tdsearch" | "tdrec" | "qbsearch" | "qbisrc" | "qbrec" | "pdsearch" | "pdisrc" | "pdrec" | "ftts" | "speak" | "phsearch" | "pornhub" | "porn" | "tts" | "jssearch" | "jsrec" | "local" | "http" | "https" | "link" | "uri" | "youtube" | "yt" | "youtube music" | "youtubemusic" | "ytm" | "musicyoutube" | "music youtube" | "soundcloud" | "sc" | "am" | "apple music" | "applemusic" | "apple" | "musicapple" | "music apple" | "sp" | "spsuggestion" | "spotify" | "spotify.com" | "spotifycom" | "dz" | "deezer" | "yandex" | "yandex music" | "yandexmusic" | "vk" | "vk music" | "vkmusic" | "tidal" | "tidal music" | "qobuz" | "pandora" | "pd" | "pandora music" | "pandoramusic" | "flowerytts" | "flowery" | "flowery.tts" | "bandcamp" | "bc" | "js" | "jiosaavn" | "td";
484
550
  };
551
+ /**
552
+ * Validates the provided source string against the capabilities of the Lavalink node. It checks if the source string is supported by the node's enabled source managers and plugins, throwing errors if any required sources or plugins are missing for the specified search platform. This ensures that search queries are only executed with compatible sources based on the node's configuration.
553
+ * @param node
554
+ * @param sourceString
555
+ * @returns
556
+ */
485
557
  validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
486
558
  }
487
559
  /**
@@ -3842,6 +3914,8 @@ interface ManagerPlayerOptions<CustomPlayerT extends Player = Player> {
3842
3914
  clientBasedPositionUpdateInterval?: number;
3843
3915
  /** What should be used as a searchPlatform, if no source was provided during the query */
3844
3916
  defaultSearchPlatform?: SearchPlatform;
3917
+ /** Allow custom sources which lavalink-client does not support (yet) */
3918
+ allowCustomSources?: boolean;
3845
3919
  /** Applies the volume via a filter, not via the lavalink volume transformer */
3846
3920
  applyVolumeAsFilter?: boolean;
3847
3921
  /** Transforms the saved data of a requested user */
@@ -4016,6 +4090,7 @@ declare class LavalinkManager<CustomPlayerT extends Player = Player> extends Eve
4016
4090
  * applyVolumeAsFilter: false,
4017
4091
  * clientBasedPositionUpdateInterval: 150,
4018
4092
  * defaultSearchPlatform: "ytmsearch",
4093
+ * allowCustomSources: false,
4019
4094
  * volumeDecrementer: 0.75,
4020
4095
  * //requesterTransformer: YourRequesterTransformerFunction,
4021
4096
  * onDisconnect: {
package/dist/index.d.ts CHANGED
@@ -417,7 +417,19 @@ declare function parseLavalinkConnUrl(connectionUrl: string): {
417
417
  declare class ManagerUtils {
418
418
  LavalinkManager: LavalinkManager | undefined;
419
419
  constructor(LavalinkManager?: LavalinkManager);
420
+ /**
421
+ * Builds a pluginInfo object based on the provided data, extracting relevant information from the data and clientData parameters. This function is used to construct the pluginInfo property for tracks, allowing for consistent handling of plugin-related information across different track sources and formats.
422
+ * @param data
423
+ * @param clientData
424
+ * @returns
425
+ */
420
426
  buildPluginInfo(data: any, clientData?: any): any;
427
+ /**
428
+ * Builds a Track object from the provided data and requester information. It validates the presence of required properties in the data, transforms the requester using a custom transformer function if provided, and constructs a Track object with the appropriate properties and plugin information. The function also includes error handling to ensure that the input data is valid and provides debug information if track building fails.
429
+ * @param data
430
+ * @param requester
431
+ * @returns
432
+ */
421
433
  buildTrack(data: LavalinkTrack | Track, requester: unknown): Track;
422
434
  /**
423
435
  * Builds a UnresolvedTrack to be resolved before being played .
@@ -430,6 +442,11 @@ declare class ManagerUtils {
430
442
  * @param data
431
443
  */
432
444
  isNode(data: LavalinkNode): boolean;
445
+ /**
446
+ * Gets the transformed requester based on the LavalinkManager options. If a custom requester transformer function is provided in the player options, it applies that function to the requester; otherwise, it returns the requester as is. The function also includes error handling to catch any exceptions that may occur during the transformation process and emits a debug event if the transformation fails.
447
+ * @param requester
448
+ * @returns
449
+ */
433
450
  getTransformedRequester(requester: unknown): unknown;
434
451
  /**
435
452
  * Validate if a data is equal to node options
@@ -470,18 +487,73 @@ declare class ManagerUtils {
470
487
  * @param track
471
488
  */
472
489
  isUnresolvedTrackQuery(data: UnresolvedQuery): boolean;
490
+ /**
491
+ * Gets the closest track by resolving the provided UnresolvedTrack using the getClosestTrack function. It includes error handling to catch any exceptions that may occur during the resolution process and emits a debug event if the resolution fails. The function returns a Promise that resolves to a Track object if successful, or undefined if no closest track is found.
492
+ * @param data
493
+ * @param player
494
+ * @returns
495
+ */
473
496
  getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
474
- validateQueryString(node: LavalinkNode, queryString: string, sourceString?: LavalinkSearchPlatform): void;
497
+ /**
498
+ * Validates the query string against various criteria, including checking for empty strings, length limits for specific sources, blacklisted links or words, and ensuring that the Lavalink node has the necessary source managers enabled for the provided query. The function also includes debug event emissions to assist with troubleshooting and understanding the validation process.
499
+ * @param node
500
+ * @param queryString
501
+ * @param sourceString
502
+ * @returns
503
+ */
504
+ validateQueryString(node: LavalinkNode, queryString: string, sourceString?: SearchPlatform): void;
505
+ /**
506
+ * Finds the source of a query string by checking if it starts with a valid source prefix defined in the DefaultSources object. If a valid source prefix is found, it returns the corresponding SearchPlatform; otherwise, it returns null. This function is useful for determining the intended search platform for a given query string, allowing for more accurate search results when the user specifies a source (e.g., "ytsearch:Never Gonna Give You Up" would indicate that the search should be performed on YouTube).
507
+ * @param queryString
508
+ * @returns
509
+ */
510
+ findSourceOfQuery(queryString: string): SearchPlatform;
511
+ /**
512
+ * Extracts the source from the query if it starts with a valid source prefix (e.g., "ytsearch:") and updates the searchQuery object accordingly.
513
+ * @param searchQuery
514
+ * @returns The updated searchQuery object with the extracted source and modified query string.
515
+ */
516
+ extractSourceOfQuery<T extends {
517
+ query: string;
518
+ source?: string;
519
+ }>(searchQuery: T): T;
520
+ /**
521
+ * Converts a string to lowercase if the input is a string, otherwise returns the input as is. This is useful for ensuring that search platform identifiers are case-insensitive while allowing other types of input to pass through unchanged.
522
+ * @param input
523
+ * @returns
524
+ */
525
+ typedLowerCase<T extends unknown>(input: T): T;
526
+ /**
527
+ * Transforms a search query by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, and the determined search platform to be used for the search operation.
528
+ * @param query
529
+ * @returns
530
+ */
475
531
  transformQuery(query: SearchQuery): {
476
532
  query: string;
477
- extraQueryUrlParams: URLSearchParams;
478
- source: any;
533
+ extraQueryUrlParams: any;
534
+ source: SearchPlatform;
479
535
  };
536
+ /**
537
+ * Transforms a LavaSearchQuery by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, the determined search platform to be used for the search operation, and the types of search (track, playlist, artist, album, text) to be performed.
538
+ * @param query
539
+ * @returns
540
+ */
480
541
  transformLavaSearchQuery(query: LavaSearchQuery): {
542
+ query: never;
543
+ types: any[];
544
+ extraQueryUrlParams: any;
545
+ source: SearchPlatform;
546
+ } | {
481
547
  query: string;
482
548
  types: string[];
483
- source: any;
549
+ source: "ytsearch" | "ytmsearch" | "scsearch" | "bcsearch" | "spsearch" | "sprec" | "amsearch" | "dzsearch" | "dzisrc" | "dzrec" | "ymsearch" | "ymrec" | "vksearch" | "vkrec" | "tdsearch" | "tdrec" | "qbsearch" | "qbisrc" | "qbrec" | "pdsearch" | "pdisrc" | "pdrec" | "ftts" | "speak" | "phsearch" | "pornhub" | "porn" | "tts" | "jssearch" | "jsrec" | "local" | "http" | "https" | "link" | "uri" | "youtube" | "yt" | "youtube music" | "youtubemusic" | "ytm" | "musicyoutube" | "music youtube" | "soundcloud" | "sc" | "am" | "apple music" | "applemusic" | "apple" | "musicapple" | "music apple" | "sp" | "spsuggestion" | "spotify" | "spotify.com" | "spotifycom" | "dz" | "deezer" | "yandex" | "yandex music" | "yandexmusic" | "vk" | "vk music" | "vkmusic" | "tidal" | "tidal music" | "qobuz" | "pandora" | "pd" | "pandora music" | "pandoramusic" | "flowerytts" | "flowery" | "flowery.tts" | "bandcamp" | "bc" | "js" | "jiosaavn" | "td";
484
550
  };
551
+ /**
552
+ * Validates the provided source string against the capabilities of the Lavalink node. It checks if the source string is supported by the node's enabled source managers and plugins, throwing errors if any required sources or plugins are missing for the specified search platform. This ensures that search queries are only executed with compatible sources based on the node's configuration.
553
+ * @param node
554
+ * @param sourceString
555
+ * @returns
556
+ */
485
557
  validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
486
558
  }
487
559
  /**
@@ -3842,6 +3914,8 @@ interface ManagerPlayerOptions<CustomPlayerT extends Player = Player> {
3842
3914
  clientBasedPositionUpdateInterval?: number;
3843
3915
  /** What should be used as a searchPlatform, if no source was provided during the query */
3844
3916
  defaultSearchPlatform?: SearchPlatform;
3917
+ /** Allow custom sources which lavalink-client does not support (yet) */
3918
+ allowCustomSources?: boolean;
3845
3919
  /** Applies the volume via a filter, not via the lavalink volume transformer */
3846
3920
  applyVolumeAsFilter?: boolean;
3847
3921
  /** Transforms the saved data of a requested user */
@@ -4016,6 +4090,7 @@ declare class LavalinkManager<CustomPlayerT extends Player = Player> extends Eve
4016
4090
  * applyVolumeAsFilter: false,
4017
4091
  * clientBasedPositionUpdateInterval: 150,
4018
4092
  * defaultSearchPlatform: "ytmsearch",
4093
+ * allowCustomSources: false,
4019
4094
  * volumeDecrementer: 0.75,
4020
4095
  * //requesterTransformer: YourRequesterTransformerFunction,
4021
4096
  * onDisconnect: {
package/dist/index.js CHANGED
@@ -604,12 +604,24 @@ var ManagerUtils = class {
604
604
  constructor(LavalinkManager2) {
605
605
  this.LavalinkManager = LavalinkManager2;
606
606
  }
607
+ /**
608
+ * Builds a pluginInfo object based on the provided data, extracting relevant information from the data and clientData parameters. This function is used to construct the pluginInfo property for tracks, allowing for consistent handling of plugin-related information across different track sources and formats.
609
+ * @param data
610
+ * @param clientData
611
+ * @returns
612
+ */
607
613
  buildPluginInfo(data, clientData = {}) {
608
614
  return {
609
615
  clientData,
610
616
  ...data.pluginInfo || data.plugin
611
617
  };
612
618
  }
619
+ /**
620
+ * Builds a Track object from the provided data and requester information. It validates the presence of required properties in the data, transforms the requester using a custom transformer function if provided, and constructs a Track object with the appropriate properties and plugin information. The function also includes error handling to ensure that the input data is valid and provides debug information if track building fails.
621
+ * @param data
622
+ * @param requester
623
+ * @returns
624
+ */
613
625
  buildTrack(data, requester) {
614
626
  if (!data?.encoded || typeof data.encoded !== "string")
615
627
  throw new RangeError("Argument 'data.encoded' must be present.");
@@ -707,6 +719,11 @@ var ManagerUtils = class {
707
719
  return false;
708
720
  return true;
709
721
  }
722
+ /**
723
+ * Gets the transformed requester based on the LavalinkManager options. If a custom requester transformer function is provided in the player options, it applies that function to the requester; otherwise, it returns the requester as is. The function also includes error handling to catch any exceptions that may occur during the transformation process and emits a debug event if the transformation fails.
724
+ * @param requester
725
+ * @returns
726
+ */
710
727
  getTransformedRequester(requester) {
711
728
  try {
712
729
  return typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer(requester) : requester;
@@ -795,6 +812,12 @@ var ManagerUtils = class {
795
812
  isUnresolvedTrackQuery(data) {
796
813
  return typeof data === "object" && !("info" in data) && typeof data.title === "string";
797
814
  }
815
+ /**
816
+ * Gets the closest track by resolving the provided UnresolvedTrack using the getClosestTrack function. It includes error handling to catch any exceptions that may occur during the resolution process and emits a debug event if the resolution fails. The function returns a Promise that resolves to a Track object if successful, or undefined if no closest track is found.
817
+ * @param data
818
+ * @param player
819
+ * @returns
820
+ */
798
821
  async getClosestTrack(data, player) {
799
822
  try {
800
823
  return getClosestTrack(data, player);
@@ -810,6 +833,13 @@ var ManagerUtils = class {
810
833
  throw e;
811
834
  }
812
835
  }
836
+ /**
837
+ * Validates the query string against various criteria, including checking for empty strings, length limits for specific sources, blacklisted links or words, and ensuring that the Lavalink node has the necessary source managers enabled for the provided query. The function also includes debug event emissions to assist with troubleshooting and understanding the validation process.
838
+ * @param node
839
+ * @param queryString
840
+ * @param sourceString
841
+ * @returns
842
+ */
813
843
  validateQueryString(node, queryString, sourceString) {
814
844
  if (!node.info) throw new Error("No Lavalink Node was provided");
815
845
  if (node._checkForSources && !node.info.sourceManagers?.length)
@@ -897,24 +927,84 @@ var ManagerUtils = class {
897
927
  }
898
928
  return;
899
929
  }
900
- transformQuery(query) {
901
- const sourceOfQuery = typeof query === "string" ? void 0 : DefaultSources[query.source?.trim?.()?.toLowerCase?.() ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? query.source?.trim?.()?.toLowerCase?.();
902
- const Query = {
903
- query: typeof query === "string" ? query : query.query,
904
- extraQueryUrlParams: typeof query !== "string" ? query.extraQueryUrlParams : void 0,
905
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
906
- };
907
- const foundSource = Object.keys(DefaultSources).find((source) => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
930
+ /**
931
+ * Finds the source of a query string by checking if it starts with a valid source prefix defined in the DefaultSources object. If a valid source prefix is found, it returns the corresponding SearchPlatform; otherwise, it returns null. This function is useful for determining the intended search platform for a given query string, allowing for more accurate search results when the user specifies a source (e.g., "ytsearch:Never Gonna Give You Up" would indicate that the search should be performed on YouTube).
932
+ * @param queryString
933
+ * @returns
934
+ */
935
+ findSourceOfQuery(queryString) {
936
+ const foundSource = Object.keys(DefaultSources).find((source) => queryString?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
908
937
  if (foundSource && !["https", "http"].includes(foundSource) && DefaultSources[foundSource]) {
909
- Query.source = DefaultSources[foundSource];
910
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length);
938
+ return foundSource;
911
939
  }
912
- return Query;
940
+ return null;
913
941
  }
942
+ /**
943
+ * Extracts the source from the query if it starts with a valid source prefix (e.g., "ytsearch:") and updates the searchQuery object accordingly.
944
+ * @param searchQuery
945
+ * @returns The updated searchQuery object with the extracted source and modified query string.
946
+ */
947
+ extractSourceOfQuery(searchQuery) {
948
+ const foundSource = this.findSourceOfQuery(searchQuery.query);
949
+ if (foundSource) {
950
+ searchQuery.source = DefaultSources[foundSource];
951
+ searchQuery.query = searchQuery.query.slice(`${foundSource}:`.length, searchQuery.query.length);
952
+ }
953
+ return searchQuery;
954
+ }
955
+ /**
956
+ * Converts a string to lowercase if the input is a string, otherwise returns the input as is. This is useful for ensuring that search platform identifiers are case-insensitive while allowing other types of input to pass through unchanged.
957
+ * @param input
958
+ * @returns
959
+ */
960
+ typedLowerCase(input) {
961
+ if (!input) return input;
962
+ if (typeof input === "string") return input.toLowerCase();
963
+ return input;
964
+ }
965
+ /**
966
+ * Transforms a search query by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, and the determined search platform to be used for the search operation.
967
+ * @param query
968
+ * @returns
969
+ */
970
+ transformQuery(query) {
971
+ const typedDefault = this.typedLowerCase(this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform);
972
+ if (typeof query === "string") {
973
+ const Query = {
974
+ query,
975
+ extraQueryUrlParams: void 0,
976
+ source: typedDefault
977
+ };
978
+ return this.extractSourceOfQuery(Query);
979
+ }
980
+ const providedSource = query?.source?.trim?.()?.toLowerCase?.();
981
+ const validSourceExtracted = DefaultSources[providedSource ?? typedDefault];
982
+ return this.extractSourceOfQuery({
983
+ query: query.query,
984
+ extraQueryUrlParams: query.extraQueryUrlParams,
985
+ source: validSourceExtracted ?? providedSource ?? typedDefault
986
+ });
987
+ }
988
+ /**
989
+ * Transforms a LavaSearchQuery by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, the determined search platform to be used for the search operation, and the types of search (track, playlist, artist, album, text) to be performed.
990
+ * @param query
991
+ * @returns
992
+ */
914
993
  transformLavaSearchQuery(query) {
915
- const sourceOfQuery = typeof query === "string" ? void 0 : DefaultSources[query.source?.trim?.()?.toLowerCase?.() ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? query.source?.trim?.()?.toLowerCase?.();
994
+ const typedDefault = this.typedLowerCase(this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform);
995
+ if (typeof query === "string") {
996
+ const Query2 = {
997
+ query,
998
+ types: [],
999
+ extraQueryUrlParams: void 0,
1000
+ source: typedDefault
1001
+ };
1002
+ return this.extractSourceOfQuery(Query2);
1003
+ }
1004
+ const providedSource = query?.source?.trim?.()?.toLowerCase?.();
1005
+ const validSourceExtracted = DefaultSources[providedSource ?? typedDefault];
916
1006
  const Query = {
917
- query: typeof query === "string" ? query : query.query,
1007
+ query: query.query,
918
1008
  types: query.types ? ["track", "playlist", "artist", "album", "text"].filter(
919
1009
  (v) => query.types?.find((x) => x.toLowerCase().startsWith(v))
920
1010
  ) : [
@@ -924,19 +1014,23 @@ var ManagerUtils = class {
924
1014
  "album"
925
1015
  /*"text"*/
926
1016
  ],
927
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
1017
+ source: validSourceExtracted ?? providedSource ?? typedDefault
928
1018
  };
929
- const foundSource = Object.keys(DefaultSources).find((source) => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
930
- if (foundSource && DefaultSources[foundSource]) {
931
- Query.source = DefaultSources[foundSource];
932
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length);
933
- }
934
- return Query;
1019
+ return this.extractSourceOfQuery(Query);
935
1020
  }
1021
+ /**
1022
+ * Validates the provided source string against the capabilities of the Lavalink node. It checks if the source string is supported by the node's enabled source managers and plugins, throwing errors if any required sources or plugins are missing for the specified search platform. This ensures that search queries are only executed with compatible sources based on the node's configuration.
1023
+ * @param node
1024
+ * @param sourceString
1025
+ * @returns
1026
+ */
936
1027
  validateSourceString(node, sourceString) {
937
1028
  if (!sourceString) throw new Error(`No SourceString was provided`);
938
1029
  const source = DefaultSources[sourceString.toLowerCase().trim()];
939
- if (!source) throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
1030
+ if (!source && !!this.LavalinkManager.options.playerOptions.allowCustomSources)
1031
+ throw new Error(
1032
+ `Lavalink-Client does not support SearchQuerySource: '${sourceString}'. You can disable this check by setting 'ManagerOptions.PlayerOptions.allowCustomSources' to true`
1033
+ );
940
1034
  if (!node.info) throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
941
1035
  if (!node._checkForSources) return;
942
1036
  if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
@@ -6072,6 +6166,7 @@ var LavalinkManager = class extends import_events2.EventEmitter {
6072
6166
  applyVolumeAsFilter: options?.playerOptions?.applyVolumeAsFilter ?? false,
6073
6167
  clientBasedPositionUpdateInterval: options?.playerOptions?.clientBasedPositionUpdateInterval ?? 100,
6074
6168
  defaultSearchPlatform: options?.playerOptions?.defaultSearchPlatform ?? "ytsearch",
6169
+ allowCustomSources: options?.playerOptions?.allowCustomSources ?? false,
6075
6170
  onDisconnect: {
6076
6171
  destroyPlayer: options?.playerOptions?.onDisconnect?.destroyPlayer ?? true,
6077
6172
  autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false,
@@ -6188,6 +6283,7 @@ var LavalinkManager = class extends import_events2.EventEmitter {
6188
6283
  * applyVolumeAsFilter: false,
6189
6284
  * clientBasedPositionUpdateInterval: 150,
6190
6285
  * defaultSearchPlatform: "ytmsearch",
6286
+ * allowCustomSources: false,
6191
6287
  * volumeDecrementer: 0.75,
6192
6288
  * //requesterTransformer: YourRequesterTransformerFunction,
6193
6289
  * onDisconnect: {
package/dist/index.mjs CHANGED
@@ -540,12 +540,24 @@ var ManagerUtils = class {
540
540
  constructor(LavalinkManager2) {
541
541
  this.LavalinkManager = LavalinkManager2;
542
542
  }
543
+ /**
544
+ * Builds a pluginInfo object based on the provided data, extracting relevant information from the data and clientData parameters. This function is used to construct the pluginInfo property for tracks, allowing for consistent handling of plugin-related information across different track sources and formats.
545
+ * @param data
546
+ * @param clientData
547
+ * @returns
548
+ */
543
549
  buildPluginInfo(data, clientData = {}) {
544
550
  return {
545
551
  clientData,
546
552
  ...data.pluginInfo || data.plugin
547
553
  };
548
554
  }
555
+ /**
556
+ * Builds a Track object from the provided data and requester information. It validates the presence of required properties in the data, transforms the requester using a custom transformer function if provided, and constructs a Track object with the appropriate properties and plugin information. The function also includes error handling to ensure that the input data is valid and provides debug information if track building fails.
557
+ * @param data
558
+ * @param requester
559
+ * @returns
560
+ */
549
561
  buildTrack(data, requester) {
550
562
  if (!data?.encoded || typeof data.encoded !== "string")
551
563
  throw new RangeError("Argument 'data.encoded' must be present.");
@@ -643,6 +655,11 @@ var ManagerUtils = class {
643
655
  return false;
644
656
  return true;
645
657
  }
658
+ /**
659
+ * Gets the transformed requester based on the LavalinkManager options. If a custom requester transformer function is provided in the player options, it applies that function to the requester; otherwise, it returns the requester as is. The function also includes error handling to catch any exceptions that may occur during the transformation process and emits a debug event if the transformation fails.
660
+ * @param requester
661
+ * @returns
662
+ */
646
663
  getTransformedRequester(requester) {
647
664
  try {
648
665
  return typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer(requester) : requester;
@@ -731,6 +748,12 @@ var ManagerUtils = class {
731
748
  isUnresolvedTrackQuery(data) {
732
749
  return typeof data === "object" && !("info" in data) && typeof data.title === "string";
733
750
  }
751
+ /**
752
+ * Gets the closest track by resolving the provided UnresolvedTrack using the getClosestTrack function. It includes error handling to catch any exceptions that may occur during the resolution process and emits a debug event if the resolution fails. The function returns a Promise that resolves to a Track object if successful, or undefined if no closest track is found.
753
+ * @param data
754
+ * @param player
755
+ * @returns
756
+ */
734
757
  async getClosestTrack(data, player) {
735
758
  try {
736
759
  return getClosestTrack(data, player);
@@ -746,6 +769,13 @@ var ManagerUtils = class {
746
769
  throw e;
747
770
  }
748
771
  }
772
+ /**
773
+ * Validates the query string against various criteria, including checking for empty strings, length limits for specific sources, blacklisted links or words, and ensuring that the Lavalink node has the necessary source managers enabled for the provided query. The function also includes debug event emissions to assist with troubleshooting and understanding the validation process.
774
+ * @param node
775
+ * @param queryString
776
+ * @param sourceString
777
+ * @returns
778
+ */
749
779
  validateQueryString(node, queryString, sourceString) {
750
780
  if (!node.info) throw new Error("No Lavalink Node was provided");
751
781
  if (node._checkForSources && !node.info.sourceManagers?.length)
@@ -833,24 +863,84 @@ var ManagerUtils = class {
833
863
  }
834
864
  return;
835
865
  }
836
- transformQuery(query) {
837
- const sourceOfQuery = typeof query === "string" ? void 0 : DefaultSources[query.source?.trim?.()?.toLowerCase?.() ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? query.source?.trim?.()?.toLowerCase?.();
838
- const Query = {
839
- query: typeof query === "string" ? query : query.query,
840
- extraQueryUrlParams: typeof query !== "string" ? query.extraQueryUrlParams : void 0,
841
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
842
- };
843
- const foundSource = Object.keys(DefaultSources).find((source) => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
866
+ /**
867
+ * Finds the source of a query string by checking if it starts with a valid source prefix defined in the DefaultSources object. If a valid source prefix is found, it returns the corresponding SearchPlatform; otherwise, it returns null. This function is useful for determining the intended search platform for a given query string, allowing for more accurate search results when the user specifies a source (e.g., "ytsearch:Never Gonna Give You Up" would indicate that the search should be performed on YouTube).
868
+ * @param queryString
869
+ * @returns
870
+ */
871
+ findSourceOfQuery(queryString) {
872
+ const foundSource = Object.keys(DefaultSources).find((source) => queryString?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
844
873
  if (foundSource && !["https", "http"].includes(foundSource) && DefaultSources[foundSource]) {
845
- Query.source = DefaultSources[foundSource];
846
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length);
874
+ return foundSource;
847
875
  }
848
- return Query;
876
+ return null;
849
877
  }
878
+ /**
879
+ * Extracts the source from the query if it starts with a valid source prefix (e.g., "ytsearch:") and updates the searchQuery object accordingly.
880
+ * @param searchQuery
881
+ * @returns The updated searchQuery object with the extracted source and modified query string.
882
+ */
883
+ extractSourceOfQuery(searchQuery) {
884
+ const foundSource = this.findSourceOfQuery(searchQuery.query);
885
+ if (foundSource) {
886
+ searchQuery.source = DefaultSources[foundSource];
887
+ searchQuery.query = searchQuery.query.slice(`${foundSource}:`.length, searchQuery.query.length);
888
+ }
889
+ return searchQuery;
890
+ }
891
+ /**
892
+ * Converts a string to lowercase if the input is a string, otherwise returns the input as is. This is useful for ensuring that search platform identifiers are case-insensitive while allowing other types of input to pass through unchanged.
893
+ * @param input
894
+ * @returns
895
+ */
896
+ typedLowerCase(input) {
897
+ if (!input) return input;
898
+ if (typeof input === "string") return input.toLowerCase();
899
+ return input;
900
+ }
901
+ /**
902
+ * Transforms a search query by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, and the determined search platform to be used for the search operation.
903
+ * @param query
904
+ * @returns
905
+ */
906
+ transformQuery(query) {
907
+ const typedDefault = this.typedLowerCase(this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform);
908
+ if (typeof query === "string") {
909
+ const Query = {
910
+ query,
911
+ extraQueryUrlParams: void 0,
912
+ source: typedDefault
913
+ };
914
+ return this.extractSourceOfQuery(Query);
915
+ }
916
+ const providedSource = query?.source?.trim?.()?.toLowerCase?.();
917
+ const validSourceExtracted = DefaultSources[providedSource ?? typedDefault];
918
+ return this.extractSourceOfQuery({
919
+ query: query.query,
920
+ extraQueryUrlParams: query.extraQueryUrlParams,
921
+ source: validSourceExtracted ?? providedSource ?? typedDefault
922
+ });
923
+ }
924
+ /**
925
+ * Transforms a LavaSearchQuery by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, the determined search platform to be used for the search operation, and the types of search (track, playlist, artist, album, text) to be performed.
926
+ * @param query
927
+ * @returns
928
+ */
850
929
  transformLavaSearchQuery(query) {
851
- const sourceOfQuery = typeof query === "string" ? void 0 : DefaultSources[query.source?.trim?.()?.toLowerCase?.() ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? query.source?.trim?.()?.toLowerCase?.();
930
+ const typedDefault = this.typedLowerCase(this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform);
931
+ if (typeof query === "string") {
932
+ const Query2 = {
933
+ query,
934
+ types: [],
935
+ extraQueryUrlParams: void 0,
936
+ source: typedDefault
937
+ };
938
+ return this.extractSourceOfQuery(Query2);
939
+ }
940
+ const providedSource = query?.source?.trim?.()?.toLowerCase?.();
941
+ const validSourceExtracted = DefaultSources[providedSource ?? typedDefault];
852
942
  const Query = {
853
- query: typeof query === "string" ? query : query.query,
943
+ query: query.query,
854
944
  types: query.types ? ["track", "playlist", "artist", "album", "text"].filter(
855
945
  (v) => query.types?.find((x) => x.toLowerCase().startsWith(v))
856
946
  ) : [
@@ -860,19 +950,23 @@ var ManagerUtils = class {
860
950
  "album"
861
951
  /*"text"*/
862
952
  ],
863
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
953
+ source: validSourceExtracted ?? providedSource ?? typedDefault
864
954
  };
865
- const foundSource = Object.keys(DefaultSources).find((source) => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
866
- if (foundSource && DefaultSources[foundSource]) {
867
- Query.source = DefaultSources[foundSource];
868
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length);
869
- }
870
- return Query;
955
+ return this.extractSourceOfQuery(Query);
871
956
  }
957
+ /**
958
+ * Validates the provided source string against the capabilities of the Lavalink node. It checks if the source string is supported by the node's enabled source managers and plugins, throwing errors if any required sources or plugins are missing for the specified search platform. This ensures that search queries are only executed with compatible sources based on the node's configuration.
959
+ * @param node
960
+ * @param sourceString
961
+ * @returns
962
+ */
872
963
  validateSourceString(node, sourceString) {
873
964
  if (!sourceString) throw new Error(`No SourceString was provided`);
874
965
  const source = DefaultSources[sourceString.toLowerCase().trim()];
875
- if (!source) throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
966
+ if (!source && !!this.LavalinkManager.options.playerOptions.allowCustomSources)
967
+ throw new Error(
968
+ `Lavalink-Client does not support SearchQuerySource: '${sourceString}'. You can disable this check by setting 'ManagerOptions.PlayerOptions.allowCustomSources' to true`
969
+ );
876
970
  if (!node.info) throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
877
971
  if (!node._checkForSources) return;
878
972
  if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
@@ -6008,6 +6102,7 @@ var LavalinkManager = class extends EventEmitter2 {
6008
6102
  applyVolumeAsFilter: options?.playerOptions?.applyVolumeAsFilter ?? false,
6009
6103
  clientBasedPositionUpdateInterval: options?.playerOptions?.clientBasedPositionUpdateInterval ?? 100,
6010
6104
  defaultSearchPlatform: options?.playerOptions?.defaultSearchPlatform ?? "ytsearch",
6105
+ allowCustomSources: options?.playerOptions?.allowCustomSources ?? false,
6011
6106
  onDisconnect: {
6012
6107
  destroyPlayer: options?.playerOptions?.onDisconnect?.destroyPlayer ?? true,
6013
6108
  autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false,
@@ -6124,6 +6219,7 @@ var LavalinkManager = class extends EventEmitter2 {
6124
6219
  * applyVolumeAsFilter: false,
6125
6220
  * clientBasedPositionUpdateInterval: 150,
6126
6221
  * defaultSearchPlatform: "ytmsearch",
6222
+ * allowCustomSources: false,
6127
6223
  * volumeDecrementer: 0.75,
6128
6224
  * //requesterTransformer: YourRequesterTransformerFunction,
6129
6225
  * onDisconnect: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients. - Supports NodeLink@v3 too.",
5
5
  "keywords": [
6
6
  "advanced",