lavalink-client 2.5.7 → 2.5.9

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 (98) hide show
  1. package/README.md +10 -2
  2. package/dist/index.d.mts +3046 -0
  3. package/dist/index.d.ts +3046 -0
  4. package/dist/index.js +4993 -0
  5. package/dist/index.mjs +4932 -0
  6. package/package.json +21 -24
  7. package/dist/cjs/index.d.ts +0 -16
  8. package/dist/cjs/index.js +0 -19
  9. package/dist/cjs/package.json +0 -3
  10. package/dist/cjs/structures/Constants.d.ts +0 -90
  11. package/dist/cjs/structures/Constants.js +0 -296
  12. package/dist/cjs/structures/CustomSearches/BandCampSearch.d.ts +0 -3
  13. package/dist/cjs/structures/CustomSearches/BandCampSearch.js +0 -39
  14. package/dist/cjs/structures/Filters.d.ts +0 -169
  15. package/dist/cjs/structures/Filters.js +0 -700
  16. package/dist/cjs/structures/LavalinkManager.d.ts +0 -232
  17. package/dist/cjs/structures/LavalinkManager.js +0 -621
  18. package/dist/cjs/structures/LavalinkManagerStatics.d.ts +0 -15
  19. package/dist/cjs/structures/LavalinkManagerStatics.js +0 -149
  20. package/dist/cjs/structures/Node.d.ts +0 -523
  21. package/dist/cjs/structures/Node.js +0 -1605
  22. package/dist/cjs/structures/NodeManager.d.ts +0 -100
  23. package/dist/cjs/structures/NodeManager.js +0 -224
  24. package/dist/cjs/structures/Player.d.ts +0 -223
  25. package/dist/cjs/structures/Player.js +0 -807
  26. package/dist/cjs/structures/Queue.d.ts +0 -186
  27. package/dist/cjs/structures/Queue.js +0 -390
  28. package/dist/cjs/structures/Types/Filters.d.ts +0 -190
  29. package/dist/cjs/structures/Types/Filters.js +0 -2
  30. package/dist/cjs/structures/Types/Manager.d.ts +0 -271
  31. package/dist/cjs/structures/Types/Manager.js +0 -2
  32. package/dist/cjs/structures/Types/Node.d.ts +0 -238
  33. package/dist/cjs/structures/Types/Node.js +0 -2
  34. package/dist/cjs/structures/Types/Player.d.ts +0 -114
  35. package/dist/cjs/structures/Types/Player.js +0 -2
  36. package/dist/cjs/structures/Types/Queue.d.ts +0 -35
  37. package/dist/cjs/structures/Types/Queue.js +0 -2
  38. package/dist/cjs/structures/Types/Track.d.ts +0 -134
  39. package/dist/cjs/structures/Types/Track.js +0 -2
  40. package/dist/cjs/structures/Types/Utils.d.ts +0 -443
  41. package/dist/cjs/structures/Types/Utils.js +0 -2
  42. package/dist/cjs/structures/Utils.d.ts +0 -116
  43. package/dist/cjs/structures/Utils.js +0 -567
  44. package/dist/esm/index.d.ts +0 -16
  45. package/dist/esm/index.js +0 -16
  46. package/dist/esm/package.json +0 -3
  47. package/dist/esm/structures/Constants.d.ts +0 -90
  48. package/dist/esm/structures/Constants.js +0 -293
  49. package/dist/esm/structures/CustomSearches/BandCampSearch.d.ts +0 -3
  50. package/dist/esm/structures/CustomSearches/BandCampSearch.js +0 -35
  51. package/dist/esm/structures/Filters.d.ts +0 -169
  52. package/dist/esm/structures/Filters.js +0 -696
  53. package/dist/esm/structures/LavalinkManager.d.ts +0 -232
  54. package/dist/esm/structures/LavalinkManager.js +0 -617
  55. package/dist/esm/structures/LavalinkManagerStatics.d.ts +0 -15
  56. package/dist/esm/structures/LavalinkManagerStatics.js +0 -146
  57. package/dist/esm/structures/Node.d.ts +0 -523
  58. package/dist/esm/structures/Node.js +0 -1600
  59. package/dist/esm/structures/NodeManager.d.ts +0 -100
  60. package/dist/esm/structures/NodeManager.js +0 -220
  61. package/dist/esm/structures/Player.d.ts +0 -223
  62. package/dist/esm/structures/Player.js +0 -803
  63. package/dist/esm/structures/Queue.d.ts +0 -186
  64. package/dist/esm/structures/Queue.js +0 -384
  65. package/dist/esm/structures/Types/Filters.d.ts +0 -190
  66. package/dist/esm/structures/Types/Filters.js +0 -1
  67. package/dist/esm/structures/Types/Manager.d.ts +0 -271
  68. package/dist/esm/structures/Types/Manager.js +0 -1
  69. package/dist/esm/structures/Types/Node.d.ts +0 -238
  70. package/dist/esm/structures/Types/Node.js +0 -1
  71. package/dist/esm/structures/Types/Player.d.ts +0 -114
  72. package/dist/esm/structures/Types/Player.js +0 -1
  73. package/dist/esm/structures/Types/Queue.d.ts +0 -35
  74. package/dist/esm/structures/Types/Queue.js +0 -1
  75. package/dist/esm/structures/Types/Track.d.ts +0 -134
  76. package/dist/esm/structures/Types/Track.js +0 -1
  77. package/dist/esm/structures/Types/Utils.d.ts +0 -443
  78. package/dist/esm/structures/Types/Utils.js +0 -1
  79. package/dist/esm/structures/Utils.d.ts +0 -116
  80. package/dist/esm/structures/Utils.js +0 -559
  81. package/dist/types/index.d.ts +0 -16
  82. package/dist/types/structures/Constants.d.ts +0 -90
  83. package/dist/types/structures/CustomSearches/BandCampSearch.d.ts +0 -3
  84. package/dist/types/structures/Filters.d.ts +0 -169
  85. package/dist/types/structures/LavalinkManager.d.ts +0 -232
  86. package/dist/types/structures/LavalinkManagerStatics.d.ts +0 -15
  87. package/dist/types/structures/Node.d.ts +0 -523
  88. package/dist/types/structures/NodeManager.d.ts +0 -100
  89. package/dist/types/structures/Player.d.ts +0 -223
  90. package/dist/types/structures/Queue.d.ts +0 -186
  91. package/dist/types/structures/Types/Filters.d.ts +0 -190
  92. package/dist/types/structures/Types/Manager.d.ts +0 -271
  93. package/dist/types/structures/Types/Node.d.ts +0 -238
  94. package/dist/types/structures/Types/Player.d.ts +0 -114
  95. package/dist/types/structures/Types/Queue.d.ts +0 -35
  96. package/dist/types/structures/Types/Track.d.ts +0 -134
  97. package/dist/types/structures/Types/Utils.d.ts +0 -443
  98. package/dist/types/structures/Utils.d.ts +0 -116
@@ -1,567 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MiniMap = exports.ManagerUtils = exports.NodeSymbol = exports.QueueSymbol = exports.UnresolvedTrackSymbol = exports.TrackSymbol = void 0;
4
- exports.parseLavalinkConnUrl = parseLavalinkConnUrl;
5
- exports.queueTrackEnd = queueTrackEnd;
6
- exports.safeStringify = safeStringify;
7
- const node_url_1 = require("node:url");
8
- const types_1 = require("node:util/types");
9
- const Constants_1 = require("./Constants.js");
10
- const LavalinkManagerStatics_1 = require("./LavalinkManagerStatics.js");
11
- exports.TrackSymbol = Symbol("LC-Track");
12
- exports.UnresolvedTrackSymbol = Symbol("LC-Track-Unresolved");
13
- exports.QueueSymbol = Symbol("LC-Queue");
14
- exports.NodeSymbol = Symbol("LC-Node");
15
- /** @hidden */
16
- const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
- /**
18
- * Parses Node Connection Url: "lavalink://<nodeId>:<nodeAuthorization(Password)>@<NodeHost>:<NodePort>"
19
- * @param connectionUrl
20
- * @returns
21
- */
22
- function parseLavalinkConnUrl(connectionUrl) {
23
- if (!connectionUrl.startsWith("lavalink://"))
24
- throw new Error(`ConnectionUrl (${connectionUrl}) must start with 'lavalink://'`);
25
- const parsed = new node_url_1.URL(connectionUrl);
26
- return {
27
- authorization: parsed.password,
28
- id: parsed.username,
29
- host: parsed.hostname,
30
- port: Number(parsed.port),
31
- };
32
- }
33
- class ManagerUtils {
34
- LavalinkManager = undefined;
35
- constructor(LavalinkManager) {
36
- this.LavalinkManager = LavalinkManager;
37
- }
38
- buildPluginInfo(data, clientData = {}) {
39
- return {
40
- clientData: clientData,
41
- ...(data.pluginInfo || data.plugin),
42
- };
43
- }
44
- buildTrack(data, requester) {
45
- if (!data?.encoded || typeof data.encoded !== "string")
46
- throw new RangeError("Argument 'data.encoded' must be present.");
47
- if (!data.info)
48
- throw new RangeError("Argument 'data.info' must be present.");
49
- try {
50
- let transformedRequester = typeof requester === "object"
51
- ? this.getTransformedRequester(requester)
52
- : undefined;
53
- if (!transformedRequester && typeof data?.userData?.requester === "object" && data.userData.requester !== null) {
54
- transformedRequester = this.getTransformedRequester(data.userData.requester);
55
- }
56
- const r = {
57
- encoded: data.encoded,
58
- info: {
59
- identifier: data.info.identifier,
60
- title: data.info.title,
61
- author: data.info.author,
62
- duration: data.info?.duration || data.info?.length,
63
- artworkUrl: data.info.artworkUrl || data.pluginInfo?.artworkUrl || data.plugin?.artworkUrl,
64
- uri: data.info.uri,
65
- sourceName: data.info.sourceName,
66
- isSeekable: data.info.isSeekable,
67
- isStream: data.info.isStream,
68
- isrc: data.info.isrc,
69
- },
70
- userData: {
71
- ...data.userData,
72
- requester: transformedRequester
73
- },
74
- pluginInfo: this.buildPluginInfo(data, "clientData" in data ? data.clientData : {}),
75
- requester: transformedRequester || this.getTransformedRequester(this.LavalinkManager?.options?.client),
76
- };
77
- Object.defineProperty(r, exports.TrackSymbol, { configurable: true, value: true });
78
- return r;
79
- }
80
- catch (error) {
81
- if (this.LavalinkManager?.options?.advancedOptions?.enableDebugEvents) {
82
- this.LavalinkManager?.emit("debug", Constants_1.DebugEvents.BuildTrackError, {
83
- error: error,
84
- functionLayer: "ManagerUtils > buildTrack()",
85
- message: "Error while building track",
86
- state: "error",
87
- });
88
- }
89
- throw new RangeError(`Argument "data" is not a valid track: ${error.message}`);
90
- }
91
- }
92
- /**
93
- * Builds a UnresolvedTrack to be resolved before being played .
94
- * @param query
95
- * @param requester
96
- */
97
- buildUnresolvedTrack(query, requester) {
98
- if (typeof query === "undefined")
99
- throw new RangeError('Argument "query" must be present.');
100
- const unresolvedTrack = {
101
- encoded: query.encoded || undefined,
102
- info: query.info ? query.info : query.title ? query : undefined,
103
- pluginInfo: this.buildPluginInfo(query),
104
- requester: this.getTransformedRequester(requester),
105
- async resolve(player) {
106
- const closest = await getClosestTrack(this, player);
107
- if (!closest)
108
- throw new SyntaxError("No closest Track found");
109
- for (const prop of Object.getOwnPropertyNames(this))
110
- delete this[prop];
111
- // delete symbol
112
- delete this[exports.UnresolvedTrackSymbol];
113
- // assign new symbol
114
- Object.defineProperty(this, exports.TrackSymbol, { configurable: true, value: true });
115
- return Object.assign(this, closest);
116
- }
117
- };
118
- if (!this.isUnresolvedTrack(unresolvedTrack))
119
- throw SyntaxError("Could not build Unresolved Track");
120
- Object.defineProperty(unresolvedTrack, exports.UnresolvedTrackSymbol, { configurable: true, value: true });
121
- return unresolvedTrack;
122
- }
123
- /**
124
- * Validate if a data is equal to a node
125
- * @param data
126
- */
127
- isNode(data) {
128
- if (!data)
129
- return false;
130
- const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(data));
131
- if (!keys.includes("constructor"))
132
- return false;
133
- if (!keys.length)
134
- return false;
135
- // all required functions
136
- if (!["connect", "destroy", "destroyPlayer", "fetchAllPlayers", "fetchInfo", "fetchPlayer", "fetchStats", "fetchVersion", "request", "updatePlayer", "updateSession"].every(v => keys.includes(v)))
137
- return false;
138
- return true;
139
- }
140
- getTransformedRequester(requester) {
141
- try {
142
- return typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function"
143
- ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer(requester)
144
- : requester;
145
- }
146
- catch (e) {
147
- if (this.LavalinkManager?.options?.advancedOptions?.enableDebugEvents) {
148
- this.LavalinkManager?.emit("debug", Constants_1.DebugEvents.TransformRequesterFunctionFailed, {
149
- error: e,
150
- functionLayer: "ManagerUtils > getTransformedRequester()",
151
- message: "Your custom transformRequesterFunction failed to execute, please check your function for errors.",
152
- state: "error",
153
- });
154
- }
155
- return requester;
156
- }
157
- }
158
- /**
159
- * Validate if a data is equal to node options
160
- * @param data
161
- */
162
- isNodeOptions(data) {
163
- if (!data || typeof data !== "object" || Array.isArray(data))
164
- return false;
165
- if (typeof data.host !== "string" || !data.host.length)
166
- return false;
167
- if (typeof data.port !== "number" || isNaN(data.port) || data.port < 0 || data.port > 65535)
168
- return false;
169
- if (typeof data.authorization !== "string" || !data.authorization.length)
170
- return false;
171
- if ("secure" in data && typeof data.secure !== "boolean" && data.secure !== undefined)
172
- return false;
173
- if ("sessionId" in data && typeof data.sessionId !== "string" && data.sessionId !== undefined)
174
- return false;
175
- if ("id" in data && typeof data.id !== "string" && data.id !== undefined)
176
- return false;
177
- if ("regions" in data && (!Array.isArray(data.regions) || !data.regions.every(v => typeof v === "string") && data.regions !== undefined))
178
- return false;
179
- if ("poolOptions" in data && typeof data.poolOptions !== "object" && data.poolOptions !== undefined)
180
- return false;
181
- if ("retryAmount" in data && (typeof data.retryAmount !== "number" || isNaN(data.retryAmount) || data.retryAmount <= 0 && data.retryAmount !== undefined))
182
- return false;
183
- if ("retryDelay" in data && (typeof data.retryDelay !== "number" || isNaN(data.retryDelay) || data.retryDelay <= 0 && data.retryDelay !== undefined))
184
- return false;
185
- if ("requestTimeout" in data && (typeof data.requestTimeout !== "number" || isNaN(data.requestTimeout) || data.requestTimeout <= 0 && data.requestTimeout !== undefined))
186
- return false;
187
- return true;
188
- }
189
- /**
190
- * Validate if a data is equal to a track
191
- * @param data the Track to validate
192
- * @returns
193
- */
194
- isTrack(data) {
195
- if (!data)
196
- return false;
197
- if (data[exports.TrackSymbol] === true)
198
- return true;
199
- return typeof data?.encoded === "string" && typeof data?.info === "object" && !("resolve" in data);
200
- }
201
- /**
202
- * Checks if the provided argument is a valid UnresolvedTrack.
203
- * @param track
204
- */
205
- isUnresolvedTrack(data) {
206
- if (!data)
207
- return false;
208
- if (data[exports.UnresolvedTrackSymbol] === true)
209
- return true;
210
- return typeof data === "object" && (("info" in data && typeof data.info.title === "string") || typeof data.encoded === "string") && "resolve" in data && typeof data.resolve === "function";
211
- }
212
- /**
213
- * Checks if the provided argument is a valid UnresolvedTrack.
214
- * @param track
215
- */
216
- isUnresolvedTrackQuery(data) {
217
- return typeof data === "object" && !("info" in data) && typeof data.title === "string";
218
- }
219
- async getClosestTrack(data, player) {
220
- try {
221
- return getClosestTrack(data, player);
222
- }
223
- catch (e) {
224
- if (this.LavalinkManager?.options?.advancedOptions?.enableDebugEvents) {
225
- this.LavalinkManager?.emit("debug", Constants_1.DebugEvents.GetClosestTrackFailed, {
226
- error: e,
227
- functionLayer: "ManagerUtils > getClosestTrack()",
228
- message: "Failed to resolve track because the getClosestTrack function failed.",
229
- state: "error",
230
- });
231
- }
232
- throw e;
233
- }
234
- }
235
- validateQueryString(node, queryString, sourceString) {
236
- if (!node.info)
237
- throw new Error("No Lavalink Node was provided");
238
- if (!node.info.sourceManagers?.length)
239
- throw new Error("Lavalink Node, has no sourceManagers enabled");
240
- if (!queryString.trim().length)
241
- throw new Error(`Query string is empty, please provide a valid query string.`);
242
- if (sourceString === "speak" && queryString.length > 100)
243
- throw new Error(`Query is speak, which is limited to 100 characters.`);
244
- // checks for blacklisted links / domains / queries
245
- if (this.LavalinkManager.options?.linksBlacklist?.length > 0) {
246
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
247
- this.LavalinkManager.emit("debug", Constants_1.DebugEvents.ValidatingBlacklistLinks, {
248
- state: "log",
249
- message: `Validating Query against LavalinkManager.options.linksBlacklist, query: "${queryString}"`,
250
- functionLayer: "(LavalinkNode > node | player) > search() > validateQueryString()",
251
- });
252
- }
253
- if (this.LavalinkManager.options?.linksBlacklist.some(v => (typeof v === "string" && (queryString.toLowerCase().includes(v.toLowerCase()) || v.toLowerCase().includes(queryString.toLowerCase()))) || (0, types_1.isRegExp)(v) && v.test(queryString))) {
254
- throw new Error(`Query string contains a link / word which is blacklisted.`);
255
- }
256
- }
257
- if (!/^https?:\/\//.test(queryString))
258
- return;
259
- else if (this.LavalinkManager.options?.linksAllowed === false)
260
- throw new Error("Using links to make a request is not allowed.");
261
- // checks for if the query is whitelisted (should only work for links, so it skips the check for no link queries)
262
- if (this.LavalinkManager.options?.linksWhitelist?.length > 0) {
263
- if (this.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
264
- this.LavalinkManager.emit("debug", Constants_1.DebugEvents.ValidatingWhitelistLinks, {
265
- state: "log",
266
- message: `Link was provided to the Query, validating against LavalinkManager.options.linksWhitelist, query: "${queryString}"`,
267
- functionLayer: "(LavalinkNode > node | player) > search() > validateQueryString()",
268
- });
269
- }
270
- if (!this.LavalinkManager.options?.linksWhitelist.some(v => (typeof v === "string" && (queryString.toLowerCase().includes(v.toLowerCase()) || v.toLowerCase().includes(queryString.toLowerCase()))) || (0, types_1.isRegExp)(v) && v.test(queryString))) {
271
- throw new Error(`Query string contains a link / word which isn't whitelisted.`);
272
- }
273
- }
274
- // missing links: beam.pro local getyarn.io clypit pornhub reddit ocreamix soundgasm
275
- if ((LavalinkManagerStatics_1.SourceLinksRegexes.YoutubeMusicRegex.test(queryString) || LavalinkManagerStatics_1.SourceLinksRegexes.YoutubeRegex.test(queryString)) && !node.info?.sourceManagers?.includes("youtube")) {
276
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'youtube' enabled");
277
- }
278
- if ((LavalinkManagerStatics_1.SourceLinksRegexes.SoundCloudMobileRegex.test(queryString) || LavalinkManagerStatics_1.SourceLinksRegexes.SoundCloudRegex.test(queryString)) && !node.info?.sourceManagers?.includes("soundcloud")) {
279
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'soundcloud' enabled");
280
- }
281
- if (LavalinkManagerStatics_1.SourceLinksRegexes.bandcamp.test(queryString) && !node.info?.sourceManagers?.includes("bandcamp")) {
282
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'bandcamp' enabled (introduced with lavaplayer 2.2.0 or lavalink 4.0.6)");
283
- }
284
- if (LavalinkManagerStatics_1.SourceLinksRegexes.TwitchTv.test(queryString) && !node.info?.sourceManagers?.includes("twitch")) {
285
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'twitch' enabled");
286
- }
287
- if (LavalinkManagerStatics_1.SourceLinksRegexes.vimeo.test(queryString) && !node.info?.sourceManagers?.includes("vimeo")) {
288
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'vimeo' enabled");
289
- }
290
- if (LavalinkManagerStatics_1.SourceLinksRegexes.tiktok.test(queryString) && !node.info?.sourceManagers?.includes("tiktok")) {
291
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'tiktok' enabled");
292
- }
293
- if (LavalinkManagerStatics_1.SourceLinksRegexes.mixcloud.test(queryString) && !node.info?.sourceManagers?.includes("mixcloud")) {
294
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'mixcloud' enabled");
295
- }
296
- if (LavalinkManagerStatics_1.SourceLinksRegexes.AllSpotifyRegex.test(queryString) && !node.info?.sourceManagers?.includes("spotify")) {
297
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'spotify' enabled");
298
- }
299
- if (LavalinkManagerStatics_1.SourceLinksRegexes.appleMusic.test(queryString) && !node.info?.sourceManagers?.includes("applemusic")) {
300
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'applemusic' enabled");
301
- }
302
- if (LavalinkManagerStatics_1.SourceLinksRegexes.AllDeezerRegex.test(queryString) && !node.info?.sourceManagers?.includes("deezer")) {
303
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'deezer' enabled");
304
- }
305
- if (LavalinkManagerStatics_1.SourceLinksRegexes.musicYandex.test(queryString) && !node.info?.sourceManagers?.includes("yandexmusic")) {
306
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'yandexmusic' enabled");
307
- }
308
- if (LavalinkManagerStatics_1.SourceLinksRegexes.jiosaavn.test(queryString) && !node.info?.sourceManagers?.includes("jiosaavn")) {
309
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled");
310
- }
311
- if (LavalinkManagerStatics_1.SourceLinksRegexes.tidal.test(queryString) && !node.info?.sourceManagers?.includes("tidal")) {
312
- throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'tidal' enabled");
313
- }
314
- return;
315
- }
316
- transformQuery(query) {
317
- const sourceOfQuery = typeof query === "string" ? undefined : (LavalinkManagerStatics_1.DefaultSources[(query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? (query.source?.trim?.()?.toLowerCase?.()));
318
- const Query = {
319
- query: typeof query === "string" ? query : query.query,
320
- extraQueryUrlParams: typeof query !== "string" ? query.extraQueryUrlParams : undefined,
321
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
322
- };
323
- const foundSource = Object.keys(LavalinkManagerStatics_1.DefaultSources).find(source => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
324
- // ignore links...
325
- if (foundSource && !["https", "http"].includes(foundSource) && LavalinkManagerStatics_1.DefaultSources[foundSource]) {
326
- Query.source = LavalinkManagerStatics_1.DefaultSources[foundSource]; // set the source to ytsearch:
327
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
328
- }
329
- return Query;
330
- }
331
- transformLavaSearchQuery(query) {
332
- // transform the query object
333
- const sourceOfQuery = typeof query === "string" ? undefined : (LavalinkManagerStatics_1.DefaultSources[(query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? (query.source?.trim?.()?.toLowerCase?.()));
334
- const Query = {
335
- query: typeof query === "string" ? query : query.query,
336
- types: query.types ? ["track", "playlist", "artist", "album", "text"].filter(v => query.types?.find(x => x.toLowerCase().startsWith(v))) : ["track", "playlist", "artist", "album", /*"text"*/],
337
- source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
338
- };
339
- const foundSource = Object.keys(LavalinkManagerStatics_1.DefaultSources).find(source => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
340
- if (foundSource && LavalinkManagerStatics_1.DefaultSources[foundSource]) {
341
- Query.source = LavalinkManagerStatics_1.DefaultSources[foundSource]; // set the source to ytsearch:
342
- Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
343
- }
344
- return Query;
345
- }
346
- validateSourceString(node, sourceString) {
347
- if (!sourceString)
348
- throw new Error(`No SourceString was provided`);
349
- const source = LavalinkManagerStatics_1.DefaultSources[sourceString.toLowerCase().trim()];
350
- if (!source)
351
- throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
352
- if (!node.info)
353
- throw new Error("Lavalink Node does not have any info cached yet, not ready yet!");
354
- if (source === "amsearch" && !node.info?.sourceManagers?.includes("applemusic")) {
355
- throw new Error("Lavalink Node has not 'applemusic' enabled, which is required to have 'amsearch' work");
356
- }
357
- if (source === "dzisrc" && !node.info?.sourceManagers?.includes("deezer")) {
358
- throw new Error("Lavalink Node has not 'deezer' enabled, which is required to have 'dzisrc' work");
359
- }
360
- if (source === "dzsearch" && !node.info?.sourceManagers?.includes("deezer")) {
361
- throw new Error("Lavalink Node has not 'deezer' enabled, which is required to have 'dzsearch' work");
362
- }
363
- if (source === "dzisrc" && node.info?.sourceManagers?.includes("deezer") && !node.info?.sourceManagers?.includes("http")) {
364
- throw new Error("Lavalink Node has not 'http' enabled, which is required to have 'dzisrc' to work");
365
- }
366
- if (source === "jsrec" && !node.info?.sourceManagers?.includes("jiosaavn")) {
367
- throw new Error("Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled, which is required to have 'jsrec' to work");
368
- }
369
- if (source === "jssearch" && !node.info?.sourceManagers?.includes("jiosaavn")) {
370
- throw new Error("Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled, which is required to have 'jssearch' to work");
371
- }
372
- if (source === "scsearch" && !node.info?.sourceManagers?.includes("soundcloud")) {
373
- throw new Error("Lavalink Node has not 'soundcloud' enabled, which is required to have 'scsearch' work");
374
- }
375
- if (source === "speak" && !node.info?.plugins?.find(c => c.name.toLowerCase().includes(LavalinkManagerStatics_1.LavalinkPlugins.DuncteBot_Plugin.toLowerCase()))) {
376
- throw new Error("Lavalink Node has not 'speak' enabled, which is required to have 'speak' work");
377
- }
378
- if (source === "tdsearch" && !node.info?.sourceManagers?.includes("tidal")) {
379
- throw new Error("Lavalink Node has not 'tidal' enabled, which is required to have 'tdsearch' work");
380
- }
381
- if (source === "tdrec" && !node.info?.sourceManagers?.includes("tidal")) {
382
- throw new Error("Lavalink Node has not 'tidal' enabled, which is required to have 'tdrec' work");
383
- }
384
- if (source === "tts" && !node.info?.plugins?.find(c => c.name.toLowerCase().includes(LavalinkManagerStatics_1.LavalinkPlugins.GoogleCloudTTS.toLowerCase()))) {
385
- throw new Error("Lavalink Node has not 'tts' enabled, which is required to have 'tts' work");
386
- }
387
- if (source === "ftts" && !(node.info?.sourceManagers?.includes("ftts") || node.info?.sourceManagers?.includes("flowery-tts") || node.info?.sourceManagers?.includes("flowerytts"))) {
388
- throw new Error("Lavalink Node has not 'flowery-tts' enabled, which is required to have 'ftts' work");
389
- }
390
- if (source === "ymsearch" && !node.info?.sourceManagers?.includes("yandexmusic")) {
391
- throw new Error("Lavalink Node has not 'yandexmusic' enabled, which is required to have 'ymsearch' work");
392
- }
393
- if (source === "ytmsearch" && !node.info.sourceManagers?.includes("youtube")) {
394
- throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytmsearch' work");
395
- }
396
- if (source === "ytsearch" && !node.info?.sourceManagers?.includes("youtube")) {
397
- throw new Error("Lavalink Node has not 'youtube' enabled, which is required to have 'ytsearch' work");
398
- }
399
- if (source === "vksearch" && !node.info?.sourceManagers?.includes("vkmusic")) {
400
- throw new Error("Lavalink Node has not 'vkmusic' enabled, which is required to have 'vksearch' work");
401
- }
402
- if (source === "vkrec" && !node.info?.sourceManagers?.includes("vkmusic")) {
403
- throw new Error("Lavalink Node has not 'vkmusic' enabled, which is required to have 'vkrec' work");
404
- }
405
- if (source === "qbsearch" && !node.info?.sourceManagers?.includes("qobuz")) {
406
- throw new Error("Lavalink Node has not 'qobuz' enabled, which is required to have 'qbsearch' work");
407
- }
408
- if (source === "qbisrc" && !node.info?.sourceManagers?.includes("qobuz")) {
409
- throw new Error("Lavalink Node has not 'qobuz' enabled, which is required to have 'qbisrc' work");
410
- }
411
- if (source === "qbrec" && !node.info?.sourceManagers?.includes("qobuz")) {
412
- throw new Error("Lavalink Node has not 'qobuz' enabled, which is required to have 'qbrec' work");
413
- }
414
- return;
415
- }
416
- }
417
- exports.ManagerUtils = ManagerUtils;
418
- class MiniMap extends Map {
419
- constructor(data = []) {
420
- super(data);
421
- }
422
- filter(fn, thisArg) {
423
- if (typeof thisArg !== 'undefined')
424
- fn = fn.bind(thisArg);
425
- const results = new this.constructor[Symbol.species]();
426
- for (const [key, val] of this) {
427
- if (fn(val, key, this))
428
- results.set(key, val);
429
- }
430
- return results;
431
- }
432
- toJSON() {
433
- return [...this.entries()];
434
- }
435
- map(fn, thisArg) {
436
- if (typeof thisArg !== 'undefined')
437
- fn = fn.bind(thisArg);
438
- const iter = this.entries();
439
- return Array.from({ length: this.size }, () => {
440
- const [key, value] = iter.next().value;
441
- return fn(value, key, this);
442
- });
443
- }
444
- }
445
- exports.MiniMap = MiniMap;
446
- async function queueTrackEnd(player, dontShiftQueue = false) {
447
- if (player.queue.current && !player.queue.current?.pluginInfo?.clientData?.previousTrack) { // If there was a current Track already and repeatmode === true, add it to the queue.
448
- player.queue.previous.unshift(player.queue.current);
449
- if (player.queue.previous.length > player.queue.options.maxPreviousTracks)
450
- player.queue.previous.splice(player.queue.options.maxPreviousTracks, player.queue.previous.length);
451
- await player.queue.utils.save();
452
- }
453
- // and if repeatMode == queue, add it back to the queue!
454
- if (player.repeatMode === "queue" && player.queue.current)
455
- player.queue.tracks.push(player.queue.current);
456
- // change the current Track to the next upcoming one
457
- const nextSong = dontShiftQueue ? null : player.queue.tracks.shift();
458
- try {
459
- if (nextSong && player.LavalinkManager.utils.isUnresolvedTrack(nextSong))
460
- await nextSong.resolve(player);
461
- player.queue.current = nextSong || null;
462
- // save it in the DB
463
- await player.queue.utils.save();
464
- }
465
- catch (error) {
466
- if (player.LavalinkManager.options?.advancedOptions?.enableDebugEvents) {
467
- player.LavalinkManager.emit("debug", Constants_1.DebugEvents.PlayerPlayUnresolvedTrackFailed, {
468
- state: "error",
469
- error: error,
470
- message: `queueTrackEnd Util was called, tried to resolve the next track, but failed to find the closest matching song`,
471
- functionLayer: "Player > play() > resolve currentTrack",
472
- });
473
- }
474
- player.LavalinkManager.emit("trackError", player, player.queue.current, error);
475
- // try to play the next track if possible
476
- if (!dontShiftQueue && player.LavalinkManager.options?.autoSkipOnResolveError === true && player.queue.tracks[0])
477
- return queueTrackEnd(player);
478
- }
479
- // return the new current Track
480
- return player.queue.current;
481
- }
482
- async function applyUnresolvedData(resTrack, data, utils) {
483
- if (!resTrack?.info || !data?.info)
484
- return;
485
- if (data.info.uri)
486
- resTrack.info.uri = data.info.uri;
487
- if (utils?.LavalinkManager?.options?.playerOptions?.useUnresolvedData === true) { // overwrite values
488
- if (data.info.artworkUrl?.length)
489
- resTrack.info.artworkUrl = data.info.artworkUrl;
490
- if (data.info.title?.length)
491
- resTrack.info.title = data.info.title;
492
- if (data.info.author?.length)
493
- resTrack.info.author = data.info.author;
494
- }
495
- else { // only overwrite if undefined / invalid
496
- if ((resTrack.info.title === 'Unknown title' || resTrack.info.title === "Unspecified description") && resTrack.info.title != data.info.title)
497
- resTrack.info.title = data.info.title;
498
- if (resTrack.info.author !== data.info.author)
499
- resTrack.info.author = data.info.author;
500
- if (resTrack.info.artworkUrl !== data.info.artworkUrl)
501
- resTrack.info.artworkUrl = data.info.artworkUrl;
502
- }
503
- for (const key of Object.keys(data.info))
504
- if (typeof resTrack.info[key] === "undefined" && key !== "resolve" && data.info[key])
505
- resTrack.info[key] = data.info[key]; // add non-existing values
506
- return resTrack;
507
- }
508
- async function getClosestTrack(data, player) {
509
- if (!player || !player.node)
510
- throw new RangeError("No player with a lavalink node was provided");
511
- if (player.LavalinkManager.utils.isTrack(data))
512
- return player.LavalinkManager.utils.buildTrack(data, data.requester);
513
- if (!player.LavalinkManager.utils.isUnresolvedTrack(data))
514
- throw new RangeError("Track is not an unresolved Track");
515
- if (!data?.info?.title && typeof data.encoded !== "string" && !data.info.uri)
516
- throw new SyntaxError("the track uri / title / encoded Base64 string is required for unresolved tracks");
517
- if (!data.requester)
518
- throw new SyntaxError("The requester is required");
519
- // try to decode the track, if possible
520
- if (typeof data.encoded === "string") {
521
- const r = await player.node.decode.singleTrack(data.encoded, data.requester);
522
- if (r)
523
- return applyUnresolvedData(r, data, player.LavalinkManager.utils);
524
- }
525
- // try to fetch the track via a uri if possible
526
- if (typeof data.info.uri === "string") {
527
- const r = await player.search({ query: data?.info?.uri }, data.requester).then(v => v.tracks?.[0]);
528
- if (r)
529
- return applyUnresolvedData(r, data, player.LavalinkManager.utils);
530
- }
531
- // search the track as closely as possible
532
- const query = [data.info?.title, data.info?.author].filter(str => !!str).join(" by ");
533
- const sourceName = data.info?.sourceName;
534
- return await player.search({
535
- query, source: sourceName !== "twitch" && sourceName !== "flowery-tts" ? sourceName : player.LavalinkManager.options?.playerOptions?.defaultSearchPlatform,
536
- }, data.requester).then((res) => {
537
- let trackToUse = null;
538
- // try to find via author name
539
- if (data.info.author && !trackToUse)
540
- trackToUse = res.tracks.find(track => [data.info?.author || "", `${data.info?.author} - Topic`].some(name => new RegExp(`^${escapeRegExp(name)}$`, "i").test(track.info?.author)) || new RegExp(`^${escapeRegExp(data.info?.title)}$`, "i").test(track.info?.title));
541
- // try to find via duration
542
- if (data.info.duration && !trackToUse)
543
- trackToUse = res.tracks.find(track => (track.info?.duration >= (data.info?.duration - 1500)) && (track?.info.duration <= (data.info?.duration + 1500)));
544
- // try to find via isrc
545
- if (data.info.isrc && !trackToUse)
546
- trackToUse = res.tracks.find(track => track.info?.isrc === data.info?.isrc);
547
- // apply unresolved data and return the track
548
- return applyUnresolvedData(trackToUse || res.tracks[0], data, player.LavalinkManager.utils);
549
- });
550
- }
551
- function safeStringify(obj, padding = 0) {
552
- const seen = new WeakSet();
553
- return JSON.stringify(obj, (key, value) => {
554
- if (typeof value === "function")
555
- return undefined; // Funktion skippen
556
- if (typeof value === "symbol")
557
- return undefined; // Symbol skippen
558
- if (typeof value === "bigint")
559
- return value.toString(); // BigInt to String
560
- if (typeof value === "object" && value !== null) {
561
- if (seen.has(value))
562
- return "[Circular]";
563
- seen.add(value);
564
- }
565
- return value;
566
- }, padding);
567
- }
@@ -1,16 +0,0 @@
1
- export * from "./structures/LavalinkManager.js";
2
- export * from "./structures/Filters.js";
3
- export * from "./structures/LavalinkManagerStatics.js";
4
- export * from "./structures/Node.js";
5
- export * from "./structures/NodeManager.js";
6
- export * from "./structures/Player.js";
7
- export * from "./structures/Queue.js";
8
- export * from "./structures/Utils.js";
9
- export * from "./structures/Types/Track.js";
10
- export * from "./structures/Types/Utils.js";
11
- export * from "./structures/Types/Filters.js";
12
- export * from "./structures/Types/Player.js";
13
- export * from "./structures/Types/Queue.js";
14
- export * from "./structures/Types/Node.js";
15
- export * from "./structures/Constants.js";
16
- export * from "./structures/Types/Manager.js";
package/dist/esm/index.js DELETED
@@ -1,16 +0,0 @@
1
- export * from "./structures/LavalinkManager.js";
2
- export * from "./structures/Filters.js";
3
- export * from "./structures/LavalinkManagerStatics.js";
4
- export * from "./structures/Node.js";
5
- export * from "./structures/NodeManager.js";
6
- export * from "./structures/Player.js";
7
- export * from "./structures/Queue.js";
8
- export * from "./structures/Utils.js";
9
- export * from "./structures/Types/Track.js";
10
- export * from "./structures/Types/Utils.js";
11
- export * from "./structures/Types/Filters.js";
12
- export * from "./structures/Types/Player.js";
13
- export * from "./structures/Types/Queue.js";
14
- export * from "./structures/Types/Node.js";
15
- export * from "./structures/Constants.js";
16
- export * from "./structures/Types/Manager.js";
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }