lavalink-client 2.2.0 → 2.2.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/README.md +76 -1
- package/dist/cjs/structures/Filters.d.ts +1 -1
- package/dist/cjs/structures/Filters.js +5 -5
- package/dist/cjs/structures/LavalinkManager.d.ts +18 -1
- package/dist/cjs/structures/LavalinkManager.js +14 -1
- package/dist/cjs/structures/LavalinkManagerStatics.d.ts +3 -0
- package/dist/cjs/structures/LavalinkManagerStatics.js +3 -0
- package/dist/cjs/structures/Node.d.ts +307 -22
- package/dist/cjs/structures/Node.js +317 -68
- package/dist/cjs/structures/Player.d.ts +44 -8
- package/dist/cjs/structures/Player.js +26 -18
- package/dist/cjs/structures/Utils.d.ts +3 -0
- package/dist/cjs/structures/Utils.js +1 -0
- package/dist/esm/structures/Filters.d.ts +1 -1
- package/dist/esm/structures/Filters.js +5 -5
- package/dist/esm/structures/LavalinkManager.d.ts +18 -1
- package/dist/esm/structures/LavalinkManager.js +14 -1
- package/dist/esm/structures/LavalinkManagerStatics.d.ts +3 -0
- package/dist/esm/structures/LavalinkManagerStatics.js +3 -0
- package/dist/esm/structures/Node.d.ts +307 -22
- package/dist/esm/structures/Node.js +317 -68
- package/dist/esm/structures/Player.d.ts +44 -8
- package/dist/esm/structures/Player.js +26 -18
- package/dist/esm/structures/Utils.d.ts +3 -0
- package/dist/esm/structures/Utils.js +1 -0
- package/dist/types/structures/Filters.d.ts +1 -1
- package/dist/types/structures/LavalinkManager.d.ts +18 -1
- package/dist/types/structures/LavalinkManagerStatics.d.ts +3 -0
- package/dist/types/structures/Node.d.ts +307 -22
- package/dist/types/structures/Player.d.ts +44 -8
- package/dist/types/structures/Utils.d.ts +3 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -59,6 +59,8 @@ yarn add tomato6966/lavalink-client
|
|
|
59
59
|
|
|
60
60
|
Check out the [Documentation](https://lc4.gitbook.io/lavalink-client) | or the [TSDocumentation](https://tomato6966.github.io/lavalink-client/) for **Examples**, and **__detailled__ Docs**, and to figure out **how to get started**. *note: it's not fully done yet (see the docs)*
|
|
61
61
|
|
|
62
|
+
- __**INFO Note**__: Please use the **[TSDocumentation (auto generated, folder `/tsDocs`)](https://tomato6966.github.io/lavalink-client/)** to get the entire information of lavalink-client, *I don't have time to update the [custom written gitbook-documentation](https://lc4.gitbook.io/lavalink-client) (folder `/docs`, feel free to update it)*
|
|
63
|
+
|
|
62
64
|
# Used in:
|
|
63
65
|
|
|
64
66
|
- [Betty](https://betty.cx/)
|
|
@@ -185,8 +187,58 @@ client.lavalink = new LavalinkManager({
|
|
|
185
187
|
})
|
|
186
188
|
```
|
|
187
189
|
|
|
190
|
+
## How to do resuming
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// 1. while the player is playing, make sure to enable it:
|
|
194
|
+
const durationToKeepPlayingInMS = 600_000;
|
|
195
|
+
await player.node.updateSession(true, durationToKeepPlayingInMS);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
// 2. make sure to have an eventlistener for resuming events somewhere
|
|
200
|
+
client.lavalink.nodeManager.on("resumed", (node, payload, fetchedPlayers) => {
|
|
201
|
+
// create players:
|
|
202
|
+
for(const fetchedPlayer of fetchedPlayers) {
|
|
203
|
+
const player = client.lavalink.createPlayer({
|
|
204
|
+
guildId: fetchedPlayer.guildId,
|
|
205
|
+
});
|
|
206
|
+
player.setVolume(fetchedPlayer.volume);
|
|
207
|
+
// and apply other things (e.g. paused, voice, filters, state, ...) (stuff like vc channel, text channel you need to store somewhere)
|
|
208
|
+
await player.queue.utils.sync(); // only works with a queuestore
|
|
209
|
+
// you can now overwride the player.queue.current track from the fetchedPlayer, or use the one from the queue.uztils.sync function
|
|
210
|
+
// continue with your resuming code...
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
```
|
|
214
|
+
|
|
188
215
|
***
|
|
189
216
|
|
|
217
|
+
|
|
218
|
+
### How to use flowertts with custom options
|
|
219
|
+
|
|
220
|
+
- First enable flowertts within the lava-src plugin
|
|
221
|
+
- Then make sure to pass through the extraQueryUrlParams object
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
const query = interaction.options.getString("text");
|
|
225
|
+
const voice = interaction.options.getString("voice");
|
|
226
|
+
|
|
227
|
+
const extraParams = new URLSearchParams();
|
|
228
|
+
if(voice) extraParams.append(`voice`, voice);
|
|
229
|
+
|
|
230
|
+
// all params for flowertts can be found here: https://flowery.pw/docs
|
|
231
|
+
const response = await player.search({
|
|
232
|
+
query: `${query}`,
|
|
233
|
+
extraQueryUrlParams: extraParams, // as of my knowledge this is currently only used for flowertts, adjusting the playback url dynamically mid-request
|
|
234
|
+
source: "ftts"
|
|
235
|
+
}, interaction.user);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
***
|
|
240
|
+
|
|
241
|
+
|
|
190
242
|
# UpdateLog
|
|
191
243
|
|
|
192
244
|
|
|
@@ -241,7 +293,7 @@ client.lavalink = new LavalinkManager({
|
|
|
241
293
|
|
|
242
294
|
# Node Resuming got supported
|
|
243
295
|
# First enable it by doing:
|
|
244
|
-
+ await player.node.
|
|
296
|
+
+ await player.node.updateSession(true, 360_000);
|
|
245
297
|
# then when reconnecting to the node add to the node.createeOptions the sessionId: "" of the previous session
|
|
246
298
|
# and after connecting the nodeManager.on("resumed", (node, payload, players) => {}) will be executed, where you can sync the players!
|
|
247
299
|
|
|
@@ -309,3 +361,26 @@ Most features of this update got tested, but if you encounter any bugs feel free
|
|
|
309
361
|
- Exporting events
|
|
310
362
|
- Added new debugOption: logCustomSearches
|
|
311
363
|
- *(Next version update i will remove the internal interval for position update, to calculations)*
|
|
364
|
+
|
|
365
|
+
## **Version 2.2.1**
|
|
366
|
+
- Player position is now calculated instead of using intervals
|
|
367
|
+
- Instaplayer fix update now requires quite good internet connection on the lavalink server due to removal of intervals for updating player.position (everything above 300mbps should be good)
|
|
368
|
+
- Internal updates for handling query params and url-requests (url-parsing) to fix quite few bugs and make the code more readable, now you don't have to ever provide stuff encoded via encodeURIComponent anymore.
|
|
369
|
+
- Added a bunch of jsdoc information, to make the autogenerated docs more accurate!
|
|
370
|
+
|
|
371
|
+
- Because of the adjustments from the encoding, you now need to pass url params for stuff like flowery tts like this:
|
|
372
|
+
|
|
373
|
+
```js
|
|
374
|
+
const query = interaction.options.getString("text");
|
|
375
|
+
const voice = interaction.options.getString("voice");
|
|
376
|
+
|
|
377
|
+
const extraParams = new URLSearchParams();
|
|
378
|
+
if(voice) extraParams.append(`voice`, voice);
|
|
379
|
+
|
|
380
|
+
// all params for flowertts can be found here: https://flowery.pw/docs
|
|
381
|
+
const response = await player.search({
|
|
382
|
+
query: `${query}`,
|
|
383
|
+
extraQueryUrlParams: extraParams, // as of my knowledge this is currently only used for flowertts, adjusting the playback url dynamically mid-request
|
|
384
|
+
source: "ftts"
|
|
385
|
+
}, interaction.user);
|
|
386
|
+
```
|
|
@@ -7,7 +7,7 @@ export declare class FilterManager {
|
|
|
7
7
|
/** The Equalizer bands currently applied to the Lavalink Server */
|
|
8
8
|
equalizerBands: EQBand[];
|
|
9
9
|
/** Private Util for the instaFix Filters option */
|
|
10
|
-
filterUpdatedState:
|
|
10
|
+
filterUpdatedState: boolean;
|
|
11
11
|
/** All "Active" / "disabled" Player Filters */
|
|
12
12
|
filters: PlayerFilters;
|
|
13
13
|
/** The Filter Data sent to Lavalink, only if the filter is enabled (ofc.) */
|
|
@@ -8,7 +8,7 @@ class FilterManager {
|
|
|
8
8
|
/** The Equalizer bands currently applied to the Lavalink Server */
|
|
9
9
|
equalizerBands = [];
|
|
10
10
|
/** Private Util for the instaFix Filters option */
|
|
11
|
-
filterUpdatedState =
|
|
11
|
+
filterUpdatedState = false;
|
|
12
12
|
/** All "Active" / "disabled" Player Filters */
|
|
13
13
|
filters = {
|
|
14
14
|
volume: false,
|
|
@@ -160,6 +160,8 @@ class FilterManager {
|
|
|
160
160
|
delete sendData[key];
|
|
161
161
|
}
|
|
162
162
|
const now = performance.now();
|
|
163
|
+
if (this.player.options.instaUpdateFiltersFix === true)
|
|
164
|
+
this.filterUpdatedState = true;
|
|
163
165
|
await this.player.node.updatePlayer({
|
|
164
166
|
guildId: this.player.guildId,
|
|
165
167
|
playerOptions: {
|
|
@@ -167,8 +169,6 @@ class FilterManager {
|
|
|
167
169
|
}
|
|
168
170
|
});
|
|
169
171
|
this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
|
|
170
|
-
if (this.player.options.instaUpdateFiltersFix === true)
|
|
171
|
-
this.filterUpdatedState = 1;
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
@@ -654,6 +654,8 @@ class FilterManager {
|
|
|
654
654
|
if (!this.player.node.sessionId)
|
|
655
655
|
throw new Error("The Lavalink-Node is either not ready or not up to date");
|
|
656
656
|
const now = performance.now();
|
|
657
|
+
if (this.player.options.instaUpdateFiltersFix === true)
|
|
658
|
+
this.filterUpdatedState = true;
|
|
657
659
|
await this.player.node.updatePlayer({
|
|
658
660
|
guildId: this.player.guildId,
|
|
659
661
|
playerOptions: {
|
|
@@ -661,8 +663,6 @@ class FilterManager {
|
|
|
661
663
|
}
|
|
662
664
|
});
|
|
663
665
|
this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
|
|
664
|
-
if (this.player.options.instaUpdateFiltersFix === true)
|
|
665
|
-
this.filterUpdatedState = 1;
|
|
666
666
|
return this;
|
|
667
667
|
}
|
|
668
668
|
/** Clears the equalizer bands. */
|
|
@@ -6,6 +6,7 @@ import { DestroyReasonsType, Player, PlayerJson, PlayerOptions } from "./Player"
|
|
|
6
6
|
import { ManagerQueueOptions } from "./Queue";
|
|
7
7
|
import { Track, UnresolvedTrack } from "./Track";
|
|
8
8
|
import { ChannelDeletePacket, GuildShardPayload, ManagerUtils, MiniMap, SearchPlatform, SponsorBlockChaptersLoaded, SponsorBlockChapterStarted, SponsorBlockSegmentSkipped, SponsorBlockSegmentsLoaded, TrackEndEvent, TrackExceptionEvent, TrackStartEvent, TrackStuckEvent, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent } from "./Utils";
|
|
9
|
+
/** How the botclient is allowed to be structured */
|
|
9
10
|
export interface BotClientOptions {
|
|
10
11
|
/** Bot Client Id */
|
|
11
12
|
id: string;
|
|
@@ -14,6 +15,7 @@ export interface BotClientOptions {
|
|
|
14
15
|
/** So users can pass entire objects / classes */
|
|
15
16
|
[x: string | number | symbol]: unknown;
|
|
16
17
|
}
|
|
18
|
+
/** Sub Manager Options, for player specific things */
|
|
17
19
|
export interface ManagerPlayerOptions {
|
|
18
20
|
/** If the Lavalink Volume should be decremented by x number */
|
|
19
21
|
volumeDecrementer?: number;
|
|
@@ -39,6 +41,7 @@ export interface ManagerPlayerOptions {
|
|
|
39
41
|
};
|
|
40
42
|
useUnresolvedData?: boolean;
|
|
41
43
|
}
|
|
44
|
+
/** Manager Options used to create the manager */
|
|
42
45
|
export interface ManagerOptions {
|
|
43
46
|
/** The Node Options, for all Nodes! (on init) */
|
|
44
47
|
nodes: LavalinkNodeOptions[];
|
|
@@ -64,6 +67,8 @@ export interface ManagerOptions {
|
|
|
64
67
|
linksAllowed?: boolean;
|
|
65
68
|
/** Advanced Options for the Library, which may or may not be "library breaking" */
|
|
66
69
|
advancedOptions?: {
|
|
70
|
+
/** Max duration for that the filter fix duration works (in ms) - default is 8mins */
|
|
71
|
+
maxFilterFixDuration?: number;
|
|
67
72
|
/** optional */
|
|
68
73
|
debugOptions?: {
|
|
69
74
|
/** For logging custom searches */
|
|
@@ -239,6 +244,7 @@ export declare class LavalinkManager extends EventEmitter {
|
|
|
239
244
|
* linksBlacklist: [],
|
|
240
245
|
* linksWhitelist: [],
|
|
241
246
|
* advancedOptions: {
|
|
247
|
+
* maxFilterFixDuration: 600_000,
|
|
242
248
|
* debugOptions: {
|
|
243
249
|
* noAudio: false,
|
|
244
250
|
* playerDestroy: {
|
|
@@ -309,10 +315,22 @@ export declare class LavalinkManager extends EventEmitter {
|
|
|
309
315
|
* Delete's a player from the cache without destroying it on lavalink (only works when it's disconnected)
|
|
310
316
|
* @param guildId
|
|
311
317
|
* @returns
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* client.lavalink.deletePlayer(interaction.guildId);
|
|
322
|
+
* // shouldn't be used except you know what you are doing.
|
|
323
|
+
* ```
|
|
312
324
|
*/
|
|
313
325
|
deletePlayer(guildId: string): boolean;
|
|
314
326
|
/**
|
|
315
327
|
* Checks wether the the lib is useable based on if any node is connected
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* if(!client.lavalink.useable) return console.error("can'T search yet, because there is no useable lavalink node.")
|
|
332
|
+
* // continue with code e.g. createing a player and searching
|
|
333
|
+
* ```
|
|
316
334
|
*/
|
|
317
335
|
get useable(): boolean;
|
|
318
336
|
/**
|
|
@@ -320,7 +338,6 @@ export declare class LavalinkManager extends EventEmitter {
|
|
|
320
338
|
* @param clientData
|
|
321
339
|
*
|
|
322
340
|
* @example
|
|
323
|
-
*
|
|
324
341
|
* ```ts
|
|
325
342
|
* // on the bot ready event
|
|
326
343
|
* client.on("ready", () => {
|
|
@@ -58,6 +58,7 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
58
58
|
queueStore: options?.queueOptions?.queueStore ?? new Queue_1.DefaultQueueStore(),
|
|
59
59
|
},
|
|
60
60
|
advancedOptions: {
|
|
61
|
+
maxFilterFixDuration: options?.advancedOptions?.maxFilterFixDuration ?? 600000,
|
|
61
62
|
debugOptions: {
|
|
62
63
|
logCustomSearches: options?.advancedOptions?.debugOptions?.logCustomSearches ?? false,
|
|
63
64
|
noAudio: options?.advancedOptions?.debugOptions?.noAudio ?? false,
|
|
@@ -150,6 +151,7 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
150
151
|
* linksBlacklist: [],
|
|
151
152
|
* linksWhitelist: [],
|
|
152
153
|
* advancedOptions: {
|
|
154
|
+
* maxFilterFixDuration: 600_000,
|
|
153
155
|
* debugOptions: {
|
|
154
156
|
* noAudio: false,
|
|
155
157
|
* playerDestroy: {
|
|
@@ -244,6 +246,12 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
244
246
|
* Delete's a player from the cache without destroying it on lavalink (only works when it's disconnected)
|
|
245
247
|
* @param guildId
|
|
246
248
|
* @returns
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* client.lavalink.deletePlayer(interaction.guildId);
|
|
253
|
+
* // shouldn't be used except you know what you are doing.
|
|
254
|
+
* ```
|
|
247
255
|
*/
|
|
248
256
|
deletePlayer(guildId) {
|
|
249
257
|
const oldPlayer = this.getPlayer(guildId);
|
|
@@ -260,6 +268,12 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
260
268
|
}
|
|
261
269
|
/**
|
|
262
270
|
* Checks wether the the lib is useable based on if any node is connected
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* if(!client.lavalink.useable) return console.error("can'T search yet, because there is no useable lavalink node.")
|
|
275
|
+
* // continue with code e.g. createing a player and searching
|
|
276
|
+
* ```
|
|
263
277
|
*/
|
|
264
278
|
get useable() {
|
|
265
279
|
return this.nodeManager.nodes.filter(v => v.connected).size > 0;
|
|
@@ -269,7 +283,6 @@ class LavalinkManager extends events_1.EventEmitter {
|
|
|
269
283
|
* @param clientData
|
|
270
284
|
*
|
|
271
285
|
* @example
|
|
272
|
-
*
|
|
273
286
|
* ```ts
|
|
274
287
|
* // on the bot ready event
|
|
275
288
|
* client.on("ready", () => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ClientCustomSearchPlatformUtils, LavalinkSearchPlatform, SearchPlatform, SourcesRegex } from "./Utils";
|
|
2
|
+
/** Default Sources Record, to allow source parsing with multiple inputs. */
|
|
2
3
|
export declare const DefaultSources: Record<SearchPlatform, LavalinkSearchPlatform | ClientCustomSearchPlatformUtils>;
|
|
4
|
+
/** Lavalink Plugins definiton */
|
|
3
5
|
export declare const LavalinkPlugins: {
|
|
4
6
|
DuncteBot_Plugin: string;
|
|
5
7
|
LavaSrc: string;
|
|
@@ -7,4 +9,5 @@ export declare const LavalinkPlugins: {
|
|
|
7
9
|
LavaSearch: string;
|
|
8
10
|
LavalinkFilterPlugin: string;
|
|
9
11
|
};
|
|
12
|
+
/** Lavalink Sources regexes for url validations */
|
|
10
13
|
export declare const SourceLinksRegexes: Record<SourcesRegex, RegExp>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SourceLinksRegexes = exports.LavalinkPlugins = exports.DefaultSources = void 0;
|
|
4
|
+
/** Default Sources Record, to allow source parsing with multiple inputs. */
|
|
4
5
|
exports.DefaultSources = {
|
|
5
6
|
// youtubemusic
|
|
6
7
|
"youtube music": "ytmsearch",
|
|
@@ -66,6 +67,7 @@ exports.DefaultSources = {
|
|
|
66
67
|
"link": "link",
|
|
67
68
|
"uri": "uri"
|
|
68
69
|
};
|
|
70
|
+
/** Lavalink Plugins definiton */
|
|
69
71
|
exports.LavalinkPlugins = {
|
|
70
72
|
DuncteBot_Plugin: "DuncteBot-plugin",
|
|
71
73
|
LavaSrc: "lavasrc-plugin",
|
|
@@ -73,6 +75,7 @@ exports.LavalinkPlugins = {
|
|
|
73
75
|
LavaSearch: "lavasearch-plugin",
|
|
74
76
|
LavalinkFilterPlugin: "lavalink-filter-plugin"
|
|
75
77
|
};
|
|
78
|
+
/** Lavalink Sources regexes for url validations */
|
|
76
79
|
exports.SourceLinksRegexes = {
|
|
77
80
|
/** DEFAULT SUPPORTED BY LAVALINK */
|
|
78
81
|
YoutubeRegex: /https?:\/\/?(?:www\.)?(?:(m|www)\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|shorts|playlist\?|watch\?v=|watch\?.+(?:&|&);v=))([a-zA-Z0-9\-_]{11})?(?:(?:\?|&|&)index=((?:\d){1,3}))?(?:(?:\?|&|&)?list=([a-zA-Z\-_0-9]{34}))?(?:\S+)?/,
|