lavalink-client 1.1.11 → 1.1.14

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.
@@ -89,6 +89,15 @@ export declare class ManagerUtils {
89
89
  isUnresolvedTrackQuery(data: UnresolvedQuery | any): boolean;
90
90
  getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
91
91
  validateQueryString(node: LavalinkNode, queryString: string): void;
92
+ transformQuery(query: SearchQuery): {
93
+ query: string;
94
+ source: any;
95
+ };
96
+ transformLavaSearchQuery(query: LavaSearchQuery): {
97
+ query: string;
98
+ types: string[];
99
+ source: any;
100
+ };
92
101
  validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
93
102
  }
94
103
  /**
@@ -322,4 +331,13 @@ export interface LavaSearchResponse {
322
331
  /** Addition result data provided by plugins */
323
332
  pluginInfo: PluginInfo;
324
333
  }
334
+ export type SearchQuery = {
335
+ query: string;
336
+ source?: SearchPlatform;
337
+ } | string;
338
+ export type LavaSearchQuery = {
339
+ query: string;
340
+ source: LavaSrcSearchPlatformBase;
341
+ types?: LavaSearchType[];
342
+ };
325
343
  export {};
@@ -153,84 +153,112 @@ export class ManagerUtils {
153
153
  if (!node.info.sourceManagers?.length)
154
154
  throw new Error("Lavalink Node, has no sourceManagers enabled");
155
155
  // missing links: beam.pro local getyarn.io clypit pornhub reddit ocreamix soundgasm
156
- if ((SourceLinksRegexes.YoutubeMusicRegex.test(queryString) || SourceLinksRegexes.YoutubeRegex.test(queryString)) && !node.info.sourceManagers.includes("youtube")) {
156
+ if ((SourceLinksRegexes.YoutubeMusicRegex.test(queryString) || SourceLinksRegexes.YoutubeRegex.test(queryString)) && !node.info?.sourceManagers?.includes("youtube")) {
157
157
  throw new Error("Lavalink Node has not 'youtube' enabled");
158
158
  }
159
- if ((SourceLinksRegexes.SoundCloudMobileRegex.test(queryString) || SourceLinksRegexes.SoundCloudRegex.test(queryString)) && !node.info.sourceManagers.includes("soundcloud")) {
159
+ if ((SourceLinksRegexes.SoundCloudMobileRegex.test(queryString) || SourceLinksRegexes.SoundCloudRegex.test(queryString)) && !node.info?.sourceManagers?.includes("soundcloud")) {
160
160
  throw new Error("Lavalink Node has not 'soundcloud' enabled");
161
161
  }
162
- if (SourceLinksRegexes.bandcamp.test(queryString) && !node.info.sourceManagers.includes("bandcamp")) {
162
+ if (SourceLinksRegexes.bandcamp.test(queryString) && !node.info?.sourceManagers?.includes("bandcamp")) {
163
163
  throw new Error("Lavalink Node has not 'bandcamp' enabled");
164
164
  }
165
- if (SourceLinksRegexes.TwitchTv.test(queryString) && !node.info.sourceManagers.includes("twitch")) {
165
+ if (SourceLinksRegexes.TwitchTv.test(queryString) && !node.info?.sourceManagers?.includes("twitch")) {
166
166
  throw new Error("Lavalink Node has not 'twitch' enabled");
167
167
  }
168
- if (SourceLinksRegexes.vimeo.test(queryString) && !node.info.sourceManagers.includes("vimeo")) {
168
+ if (SourceLinksRegexes.vimeo.test(queryString) && !node.info?.sourceManagers?.includes("vimeo")) {
169
169
  throw new Error("Lavalink Node has not 'vimeo' enabled");
170
170
  }
171
- if (SourceLinksRegexes.tiktok.test(queryString) && !node.info.sourceManagers.includes("tiktok")) {
171
+ if (SourceLinksRegexes.tiktok.test(queryString) && !node.info?.sourceManagers?.includes("tiktok")) {
172
172
  throw new Error("Lavalink Node has not 'tiktok' enabled");
173
173
  }
174
- if (SourceLinksRegexes.mixcloud.test(queryString) && !node.info.sourceManagers.includes("mixcloud")) {
174
+ if (SourceLinksRegexes.mixcloud.test(queryString) && !node.info?.sourceManagers?.includes("mixcloud")) {
175
175
  throw new Error("Lavalink Node has not 'mixcloud' enabled");
176
176
  }
177
- if (SourceLinksRegexes.AllSpotifyRegex.test(queryString) && !node.info.sourceManagers.includes("spotify")) {
177
+ if (SourceLinksRegexes.AllSpotifyRegex.test(queryString) && !node.info?.sourceManagers?.includes("spotify")) {
178
178
  throw new Error("Lavalink Node has not 'spotify' enabled");
179
179
  }
180
- if (SourceLinksRegexes.appleMusic.test(queryString) && !node.info.sourceManagers.includes("applemusic")) {
180
+ if (SourceLinksRegexes.appleMusic.test(queryString) && !node.info?.sourceManagers?.includes("applemusic")) {
181
181
  throw new Error("Lavalink Node has not 'applemusic' enabled");
182
182
  }
183
- if (SourceLinksRegexes.AllDeezerRegex.test(queryString) && !node.info.sourceManagers.includes("deezer")) {
183
+ if (SourceLinksRegexes.AllDeezerRegex.test(queryString) && !node.info?.sourceManagers?.includes("deezer")) {
184
184
  throw new Error("Lavalink Node has not 'deezer' enabled");
185
185
  }
186
- if (SourceLinksRegexes.AllDeezerRegex.test(queryString) && node.info.sourceManagers.includes("deezer") && !node.info.sourceManagers.includes("http")) {
186
+ if (SourceLinksRegexes.AllDeezerRegex.test(queryString) && node.info?.sourceManagers?.includes("deezer") && !node.info?.sourceManagers?.includes("http")) {
187
187
  throw new Error("Lavalink Node has not 'http' enabled, which is required to have 'deezer' to work");
188
188
  }
189
- if (SourceLinksRegexes.musicYandex.test(queryString) && !node.info.sourceManagers.includes("yandexmusic")) {
189
+ if (SourceLinksRegexes.musicYandex.test(queryString) && !node.info?.sourceManagers?.includes("yandexmusic")) {
190
190
  throw new Error("Lavalink Node has not 'yandexmusic' enabled");
191
191
  }
192
192
  return;
193
193
  }
194
+ transformQuery(query) {
195
+ const Query = {
196
+ query: typeof query === "string" ? query : query.query,
197
+ source: DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
198
+ };
199
+ const foundSource = Object.keys(DefaultSources).find(source => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
200
+ if (foundSource && DefaultSources[foundSource]) {
201
+ Query.source = DefaultSources[foundSource]; // set the source to ytsearch:
202
+ Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
203
+ }
204
+ return Query;
205
+ }
206
+ transformLavaSearchQuery(query) {
207
+ // transform the query object
208
+ const Query = {
209
+ query: typeof query === "string" ? query : query.query,
210
+ types: query.types ? ["track", "playlist", "artist", "album", "text"].filter(v => query.types?.find(x => x.toLowerCase().startsWith(v))) : ["track", "playlist", "artist", "album", /*"text"*/],
211
+ source: DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
212
+ };
213
+ const foundSource = Object.keys(DefaultSources).find(source => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
214
+ if (foundSource && DefaultSources[foundSource]) {
215
+ Query.source = DefaultSources[foundSource]; // set the source to ytsearch:
216
+ Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
217
+ }
218
+ return Query;
219
+ }
194
220
  validateSourceString(node, sourceString) {
195
221
  if (!sourceString)
196
222
  throw new Error(`No SourceString was provided`);
197
223
  const source = DefaultSources[sourceString.toLowerCase().trim()];
198
224
  if (!source)
199
225
  throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
200
- if (source === "amsearch" && !node.info.sourceManagers.includes("applemusic")) {
226
+ if (!node.info)
227
+ throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
228
+ if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
201
229
  throw new Error("Lavalink Node has not 'applemusic' enabled, which is required to have 'amsearch' work");
202
230
  }
203
- if (source === "dzisrc" && !node.info.sourceManagers.includes("deezer")) {
231
+ if (source === "dzisrc" && !node.info?.sourceManagers?.includes("deezer")) {
204
232
  throw new Error("Lavalink Node has not 'deezer' enabled, which is required to have 'dzisrc' work");
205
233
  }
206
- if (source === "dzsearch" && !node.info.sourceManagers.includes("deezer")) {
234
+ if (source === "dzsearch" && !node.info?.sourceManagers?.includes("deezer")) {
207
235
  throw new Error("Lavalink Node has not 'deezer' enabled, which is required to have 'dzsearch' work");
208
236
  }
209
- if (source === "dzisrc" && node.info.sourceManagers.includes("deezer") && !node.info.sourceManagers.includes("http")) {
237
+ if (source === "dzisrc" && node.info?.sourceManagers?.includes("deezer") && !node.info?.sourceManagers?.includes("http")) {
210
238
  throw new Error("Lavalink Node has not 'http' enabled, which is required to have 'dzisrc' to work");
211
239
  }
212
- if (source === "dzsearch" && node.info.sourceManagers.includes("deezer") && !node.info.sourceManagers.includes("http")) {
240
+ if (source === "dzsearch" && node.info?.sourceManagers?.includes("deezer") && !node.info?.sourceManagers?.includes("http")) {
213
241
  throw new Error("Lavalink Node has not 'http' enabled, which is required to have 'dzsearch' to work");
214
242
  }
215
- if (source === "scsearch" && !node.info.sourceManagers.includes("soundcloud")) {
243
+ if (source === "scsearch" && !node.info?.sourceManagers?.includes("soundcloud")) {
216
244
  throw new Error("Lavalink Node has not 'soundcloud' enabled, which is required to have 'scsearch' work");
217
245
  }
218
- if (source === "speak" && !node.info.plugins.find(c => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
246
+ if (source === "speak" && !node.info?.plugins?.find(c => c.name.toLowerCase().includes(LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
219
247
  throw new Error("Lavalink Node has not 'speak' enabled, which is required to have 'speak' work");
220
248
  }
221
- if (source === "tts" && !node.info.plugins.find(c => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
249
+ if (source === "tts" && !node.info?.plugins?.find(c => c.name.toLowerCase().includes(LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
222
250
  throw new Error("Lavalink Node has not 'tts' enabled, which is required to have 'tts' work");
223
251
  }
224
- if (source === "ftts" && !(node.info.sourceManagers.includes("ftts") || node.info.sourceManagers.includes("flowery-tts") || node.info.sourceManagers.includes("flowerytts"))) {
252
+ if (source === "ftts" && !(node.info?.sourceManagers?.includes("ftts") || node.info?.sourceManagers?.includes("flowery-tts") || node.info?.sourceManagers?.includes("flowerytts"))) {
225
253
  throw new Error("Lavalink Node has not 'flowery-tts' enabled, which is required to have 'ftts' work");
226
254
  }
227
- if (source === "ymsearch" && !node.info.sourceManagers.includes("yandexmusic")) {
255
+ if (source === "ymsearch" && !node.info?.sourceManagers?.includes("yandexmusic")) {
228
256
  throw new Error("Lavalink Node has not 'yandexmusic' enabled, which is required to have 'ymsearch' work");
229
257
  }
230
- if (source === "ytmsearch" && !node.info.sourceManagers.includes("youtube")) {
258
+ if (source === "ytmsearch" && !node.info.sourceManagers?.includes("youtube")) {
231
259
  throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytmsearch' work");
232
260
  }
233
- if (source === "ytsearch" && !node.info.sourceManagers.includes("youtube")) {
261
+ if (source === "ytsearch" && !node.info?.sourceManagers?.includes("youtube")) {
234
262
  throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytsearch' work");
235
263
  }
236
264
  return;
@@ -2,7 +2,7 @@
2
2
  import { Dispatcher, Pool } from "undici";
3
3
  import { NodeManager } from "./NodeManager";
4
4
  import internal from "stream";
5
- import { InvalidLavalinkRestRequest, LavalinkPlayer, PlayerUpdateInfo, RoutePlanner, Session, Base64, SearchResult } from "./Utils";
5
+ import { InvalidLavalinkRestRequest, LavalinkPlayer, PlayerUpdateInfo, RoutePlanner, Session, Base64, SearchResult, LavaSearchResponse, LavaSearchQuery, SearchQuery } from "./Utils";
6
6
  import { DestroyReasonsType } from "./Player";
7
7
  import { Track } from "./Track";
8
8
  /** Modifies any outgoing REST requests. */
@@ -135,7 +135,8 @@ export declare class LavalinkNode {
135
135
  * @returns The returned data
136
136
  */
137
137
  request(endpoint: string, modify?: ModifyRequest, parseAsText?: boolean): Promise<unknown>;
138
- search(querySourceString: string, requestUser: unknown): Promise<SearchResult>;
138
+ search(query: SearchQuery, requestUser: unknown): Promise<SearchResult>;
139
+ lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<SearchResult | LavaSearchResponse>;
139
140
  /**
140
141
  * Update the Player State on the Lavalink Server
141
142
  * @param data
@@ -160,7 +161,7 @@ export declare class LavalinkNode {
160
161
  * Destroys the Node-Connection (Websocket) and all player's of the node
161
162
  * @returns
162
163
  */
163
- destroy(destroyReason?: DestroyReasonsType): void;
164
+ destroy(destroyReason?: DestroyReasonsType, deleteNode?: boolean): void;
164
165
  /** Returns if connected to the Node. */
165
166
  get connected(): boolean;
166
167
  /**
@@ -54,6 +54,22 @@ export declare interface NodeManager {
54
54
  export declare class NodeManager extends EventEmitter {
55
55
  nodes: MiniMap<string, LavalinkNode>;
56
56
  constructor(LavalinkManager: LavalinkManager);
57
+ /**
58
+ * Disconnects all Nodes from lavalink ws sockets
59
+ * @param deleteAllNodes if the nodes should also be deleted from nodeManager.nodes
60
+ * @returns amount of disconnected Nodes
61
+ */
62
+ disconnectAll(deleteAllNodes?: boolean): Promise<number>;
63
+ /**
64
+ * Connects all not connected nodes
65
+ * @returns Amount of connected Nodes
66
+ */
67
+ connectAll(): Promise<number>;
68
+ /**
69
+ * Forcefully reconnects all nodes
70
+ * @returns amount of nodes
71
+ */
72
+ reconnectAll(): Promise<number>;
57
73
  createNode(options: LavalinkNodeOptions): LavalinkNode;
58
74
  leastUsedNodes(sortType?: "memory" | "cpuLavalink" | "cpuSystem" | "calls" | "playingPlayers" | "players"): LavalinkNode[];
59
75
  deleteNode(node: LavalinkNodeIdentifier | LavalinkNode): void;
@@ -3,8 +3,8 @@ import { LavalinkManager } from "./LavalinkManager";
3
3
  import { LavalinkNode } from "./Node";
4
4
  import { Queue } from "./Queue";
5
5
  import { Track, UnresolvedTrack } from "./Track";
6
- import { LavalinkPlayerVoiceOptions, SearchPlatform, SearchResult, LavaSearchType, LavaSearchResponse, LavaSrcSearchPlatformBase } from "./Utils";
7
- type PlayerDestroyReasons = "QueueEmpty" | "NodeDestroy" | "NodeDeleted" | "LavalinkNoVoice" | "NodeReconnectFail" | "PlayerReconnectFail" | "Disconnected" | "ChannelDeleted";
6
+ import { LavalinkPlayerVoiceOptions, SearchResult, LavaSearchResponse, LavaSearchQuery, SearchQuery } from "./Utils";
7
+ type PlayerDestroyReasons = "QueueEmpty" | "NodeDestroy" | "NodeDeleted" | "LavalinkNoVoice" | "NodeReconnectFail" | "PlayerReconnectFail" | "Disconnected" | "ChannelDeleted" | "ReconnectAllNodes" | "DisconnectAllNodes";
8
8
  export type DestroyReasonsType = PlayerDestroyReasons | string;
9
9
  export declare const DestroyReasons: Record<PlayerDestroyReasons, PlayerDestroyReasons>;
10
10
  export interface PlayerJson {
@@ -138,20 +138,13 @@ export declare class Player {
138
138
  * @param ignoreVolumeDecrementer If it should ignore the volumedecrementer option
139
139
  */
140
140
  setVolume(volume: number, ignoreVolumeDecrementer?: boolean): Promise<void>;
141
- lavaSearch(query: {
142
- query: string;
143
- source: LavaSrcSearchPlatformBase;
144
- types?: LavaSearchType[];
145
- }, requestUser: unknown): Promise<import("./Utils").UnresolvedSearchResult | SearchResult | LavaSearchResponse>;
141
+ lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<SearchResult | LavaSearchResponse>;
146
142
  /**
147
143
  *
148
144
  * @param query Query for your data
149
145
  * @param requestUser
150
146
  */
151
- search(query: {
152
- query: string;
153
- source?: SearchPlatform;
154
- } | string, requestUser: unknown): Promise<import("./Utils").UnresolvedSearchResult | SearchResult>;
147
+ search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").UnresolvedSearchResult | SearchResult>;
155
148
  /**
156
149
  * Pause the player
157
150
  */
@@ -89,6 +89,15 @@ export declare class ManagerUtils {
89
89
  isUnresolvedTrackQuery(data: UnresolvedQuery | any): boolean;
90
90
  getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
91
91
  validateQueryString(node: LavalinkNode, queryString: string): void;
92
+ transformQuery(query: SearchQuery): {
93
+ query: string;
94
+ source: any;
95
+ };
96
+ transformLavaSearchQuery(query: LavaSearchQuery): {
97
+ query: string;
98
+ types: string[];
99
+ source: any;
100
+ };
92
101
  validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
93
102
  }
94
103
  /**
@@ -322,4 +331,13 @@ export interface LavaSearchResponse {
322
331
  /** Addition result data provided by plugins */
323
332
  pluginInfo: PluginInfo;
324
333
  }
334
+ export type SearchQuery = {
335
+ query: string;
336
+ source?: SearchPlatform;
337
+ } | string;
338
+ export type LavaSearchQuery = {
339
+ query: string;
340
+ source: LavaSrcSearchPlatformBase;
341
+ types?: LavaSearchType[];
342
+ };
325
343
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "1.1.11",
3
+ "version": "1.1.14",
4
4
  "description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",