Skip to content

Commit 20414dd

Browse files
committed
format
1 parent ebd62af commit 20414dd

File tree

8 files changed

+155
-154
lines changed

8 files changed

+155
-154
lines changed

docs/src/content/docs/extra/autoplay-system.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description: "How to do make an autoplaying system."
1212
Hot-Tipp: You can use player variables in order to enable/disable this system during runtime, e.g. by `player.set("autoplay_disabled", true)` and check it in the autoplayFunction by `const isAutoPlayDisabled = player.get("autoplay_disabled") === true;`
1313

1414
E.g.:
15+
1516
```ts
1617
client.lavalink = new LavalinkManager<myCustomPlayer>({
1718
nodes: [
@@ -103,6 +104,5 @@ async function autoPlayFunction(player, lastPlayedTrack) {
103104
return;
104105
}
105106
return;
106-
};
107-
107+
}
108108
```

docs/src/content/docs/extra/version-log.mdx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@ Logs about the changed features.
1010
---
1111

1212
## **Version 2.9.2**
13+
1314
- Major fixes that may or may not change the behavior of some features, so please check the changelog for more details. - https://github.com/Tomato6966/lavalink-client/pull/174
1415
- Stuff fixed:
15-
- the queue utils sync used a wrong length for the previous.
16-
- some nullish checks were missing for the queueOptions.
17-
- removed a race condition for the Node.ts error handler
18-
- 2 fixes for filter.ts:
19-
- resetFilters didn't check for the vaporwave filter, because of copy-paste-issue.
20-
- setSpeed / setPitch / setRate overwrite each others values instead of accomodating each other...
21-
- (NEW OPTION) `ManagerOptions.playerOptions.enforceSponsorBlockRequestForEventEnablement` If this is true, then on changeNode, the sponsorblocksystem will be enabled on defeault. (default: true)
16+
- the queue utils sync used a wrong length for the previous.
17+
- some nullish checks were missing for the queueOptions.
18+
- removed a race condition for the Node.ts error handler
19+
- 2 fixes for filter.ts:
20+
- resetFilters didn't check for the vaporwave filter, because of copy-paste-issue.
21+
- setSpeed / setPitch / setRate overwrite each others values instead of accomodating each other...
22+
- (NEW OPTION) `ManagerOptions.playerOptions.enforceSponsorBlockRequestForEventEnablement` If this is true, then on changeNode, the sponsorblocksystem will be enabled on defeault. (default: true)
2223

2324
- New Event: `playerClientUpdate`
24-
* Always emits when the player (on client side) got updated via a function-call.
25-
* This is useful for example, if you want to save the player data on every update, or similar.
26-
* Emits only when you call one of those functions:
27-
* player.pause()
28-
* player.resume()
29-
* player.seek()
30-
* player.setRepeatMode()
31-
* player.setVolume()
32-
* and on every call of the filterManager.
25+
- Always emits when the player (on client side) got updated via a function-call.
26+
- This is useful for example, if you want to save the player data on every update, or similar.
27+
- Emits only when you call one of those functions:
28+
- player.pause()
29+
- player.resume()
30+
- player.seek()
31+
- player.setRepeatMode()
32+
- player.setVolume()
33+
- and on every call of the filterManager.
3334

3435
## **Version 2.9.1**
3536

src/structures/Filters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { audioOutputsData, EQList } from "./Constants";
2-
import { safeStringify } from "./Utils";
3-
42
import type { Player } from "./Player";
53
import type {
64
AudioOutputs,
@@ -10,6 +8,7 @@ import type {
108
PlayerFilters,
119
TimescaleFilter,
1210
} from "./Types/Filters";
11+
import { safeStringify } from "./Utils";
1312
/**
1413
* The FilterManager for each player
1514
*/

src/structures/LavalinkManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export class LavalinkManager<CustomPlayerT extends Player = Player> extends Even
132132
threshold: options?.playerOptions?.maxErrorsPerTime?.threshold ?? 35_000,
133133
maxAmount: options?.playerOptions?.maxErrorsPerTime?.maxAmount ?? 3,
134134
},
135-
enforceSponsorBlockRequestForEventEnablement: options?.playerOptions?.enforceSponsorBlockRequestForEventEnablement ?? true,
135+
enforceSponsorBlockRequestForEventEnablement:
136+
options?.playerOptions?.enforceSponsorBlockRequestForEventEnablement ?? true,
136137
},
137138
linksWhitelist: options?.linksWhitelist ?? [],
138139
linksBlacklist: options?.linksBlacklist ?? [],

src/structures/Node.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ export class LavalinkNode {
406406
res.loadType === "playlist"
407407
? res.data?.tracks
408408
: res.loadType === "track"
409-
? [res.data]
410-
: res.loadType === "search"
411-
? Array.isArray(res.data)
412-
? res.data
413-
: [res.data]
414-
: [];
409+
? [res.data]
410+
: res.loadType === "search"
411+
? Array.isArray(res.data)
412+
? res.data
413+
: [res.data]
414+
: [];
415415

416416
if (throwOnEmpty === true && (res.loadType === "empty" || !resTracks.length)) {
417417
this._emitDebugEvent(DebugEvents.SearchNothingFound, {
@@ -429,44 +429,44 @@ export class LavalinkNode {
429429
playlist:
430430
res.loadType === "playlist"
431431
? {
432-
name: res.data.info?.name || res.data.pluginInfo?.name || null,
433-
title: res.data.info?.name || res.data.pluginInfo?.name || null,
434-
author: res.data.info?.author || res.data.pluginInfo?.author || null,
435-
thumbnail:
436-
res.data.info?.artworkUrl ||
437-
res.data.pluginInfo?.artworkUrl ||
438-
(typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1
439-
? null
440-
: resTracks[res.data?.info?.selectedTrack]
432+
name: res.data.info?.name || res.data.pluginInfo?.name || null,
433+
title: res.data.info?.name || res.data.pluginInfo?.name || null,
434+
author: res.data.info?.author || res.data.pluginInfo?.author || null,
435+
thumbnail:
436+
res.data.info?.artworkUrl ||
437+
res.data.pluginInfo?.artworkUrl ||
438+
(typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1
439+
? null
440+
: resTracks[res.data?.info?.selectedTrack]
441441
? resTracks[res.data?.info?.selectedTrack]?.info?.artworkUrl ||
442-
resTracks[res.data?.info?.selectedTrack]?.info?.pluginInfo?.artworkUrl
442+
resTracks[res.data?.info?.selectedTrack]?.info?.pluginInfo?.artworkUrl
443443
: null) ||
444-
null,
445-
uri:
446-
res.data.info?.url ||
447-
res.data.info?.uri ||
448-
res.data.info?.link ||
449-
res.data.pluginInfo?.url ||
450-
res.data.pluginInfo?.uri ||
451-
res.data.pluginInfo?.link ||
452-
null,
453-
selectedTrack:
454-
typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1
455-
? null
456-
: resTracks[res.data?.info?.selectedTrack]
444+
null,
445+
uri:
446+
res.data.info?.url ||
447+
res.data.info?.uri ||
448+
res.data.info?.link ||
449+
res.data.pluginInfo?.url ||
450+
res.data.pluginInfo?.uri ||
451+
res.data.pluginInfo?.link ||
452+
null,
453+
selectedTrack:
454+
typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1
455+
? null
456+
: resTracks[res.data?.info?.selectedTrack]
457457
? this._LManager.utils.buildTrack(
458-
resTracks[res.data?.info?.selectedTrack],
459-
requestUser,
460-
)
458+
resTracks[res.data?.info?.selectedTrack],
459+
requestUser,
460+
)
461461
: null,
462-
duration: resTracks.length
463-
? resTracks.reduce(
464-
(acc: number, cur: Track & { info: Track["info"] & { length?: number } }) =>
465-
acc + (cur?.info?.duration || cur?.info?.length || 0),
466-
0,
467-
)
468-
: 0,
469-
}
462+
duration: resTracks.length
463+
? resTracks.reduce(
464+
(acc: number, cur: Track & { info: Track["info"] & { length?: number } }) =>
465+
acc + (cur?.info?.duration || cur?.info?.length || 0),
466+
0,
467+
)
468+
: 0,
469+
}
470470
: null,
471471
tracks: (resTracks.length
472472
? resTracks.map((t) => this._LManager.utils.buildTrack(t, requestUser))
@@ -1330,22 +1330,22 @@ export class LavalinkNode {
13301330
metrics.players === 0
13311331
? 200
13321332
: metrics.cpuLoad > 0
1333-
? Math.max(
1333+
? Math.max(
13341334
0,
13351335
Math.floor(((cpuThresholds.fair - metrics.cpuLoad) / metrics.cpuLoad) * metrics.players),
13361336
)
1337-
: 200;
1337+
: 200;
13381338
const memoryCapacity =
13391339
metrics.players === 0
13401340
? 200
13411341
: metrics.memoryUsage > 0
1342-
? Math.max(
1342+
? Math.max(
13431343
0,
13441344
Math.floor(
13451345
((memoryThresholds.fair - metrics.memoryUsage) / metrics.memoryUsage) * metrics.players,
13461346
),
13471347
)
1348-
: 200;
1348+
: 200;
13491349

13501350
// Use the more conservative estimate, capped at a reasonable maximum
13511351
estimatedRemainingCapacity = Math.min(Math.min(cpuCapacity, memoryCapacity), 500);
@@ -1824,8 +1824,8 @@ export class LavalinkNode {
18241824
payload.state.ping >= 0
18251825
? payload.state.ping
18261826
: player.ping.ws <= 0 && player.connected
1827-
? null
1828-
: player.ping.ws || 0;
1827+
? null
1828+
: player.ping.ws || 0;
18291829

18301830
if (!player.createdTimeStamp && payload.state.time) player.createdTimeStamp = payload.state.time;
18311831

src/structures/Player.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { DebugEvents } from "./Constants";
2+
import type { DestroyReasons } from "./Constants";
23
import { bandCampSearch } from "./CustomSearches/BandCampSearch";
34
import { FilterManager } from "./Filters";
4-
import { Queue, QueueSaver } from "./Queue";
5-
import { queueTrackEnd } from "./Utils";
6-
7-
import type { DestroyReasons } from "./Constants";
85
import type { LavalinkManager } from "./LavalinkManager";
96
import type { LavalinkNode } from "./Node";
107
import type { NodeLinkNode } from "./NodeLink";
8+
import { Queue, QueueSaver } from "./Queue";
119
import type { SponsorBlockSegment } from "./Types/Node";
1210
import type {
1311
anyObject,
@@ -19,6 +17,7 @@ import type {
1917
} from "./Types/Player";
2018
import type { Track, UnresolvedTrack } from "./Types/Track";
2119
import type { LavalinkPlayerVoiceOptions, LavaSearchQuery, SearchQuery } from "./Types/Utils";
20+
import { queueTrackEnd } from "./Utils";
2221
export class Player {
2322
/** Filter Manager per player */
2423
public filterManager: FilterManager;
@@ -84,12 +83,12 @@ export class Player {
8483
serverMute: boolean;
8584
suppress: boolean;
8685
} = {
87-
selfDeaf: false,
88-
selfMute: false,
89-
serverDeaf: false,
90-
serverMute: false,
91-
suppress: false,
92-
};
86+
selfDeaf: false,
87+
selfMute: false,
88+
serverDeaf: false,
89+
serverMute: false,
90+
suppress: false,
91+
};
9392

9493
/** Custom data for the player */
9594
private readonly data: Record<string, unknown> = {};
@@ -273,10 +272,10 @@ export class Player {
273272
options.clientTrack.userData = {
274273
...(typeof options?.clientTrack?.requester === "object"
275274
? {
276-
requester: this.LavalinkManager.utils.getTransformedRequester(
277-
options?.clientTrack?.requester || {},
278-
) as anyObject,
279-
}
275+
requester: this.LavalinkManager.utils.getTransformedRequester(
276+
options?.clientTrack?.requester || {},
277+
) as anyObject,
278+
}
280279
: {}),
281280
...options?.clientTrack.userData,
282281
...options.track?.userData,
@@ -313,10 +312,10 @@ export class Player {
313312
userData: {
314313
...(typeof options?.track?.requester === "object"
315314
? {
316-
requester: this.LavalinkManager.utils.getTransformedRequester(
317-
options?.track?.requester || {},
318-
),
319-
}
315+
requester: this.LavalinkManager.utils.getTransformedRequester(
316+
options?.track?.requester || {},
317+
),
318+
}
320319
: {}),
321320
...options.track.userData,
322321
},
@@ -368,10 +367,10 @@ export class Player {
368367
this.queue.current.userData = {
369368
...(typeof this.queue.current?.requester === "object"
370369
? {
371-
requester: this.LavalinkManager.utils.getTransformedRequester(
372-
this.queue.current?.requester || {},
373-
) as anyObject,
374-
}
370+
requester: this.LavalinkManager.utils.getTransformedRequester(
371+
this.queue.current?.requester || {},
372+
) as anyObject,
373+
}
375374
: {}),
376375
...this.queue.current?.userData,
377376
...options.track?.userData,
@@ -419,10 +418,10 @@ export class Player {
419418
userData: {
420419
...(typeof this.queue.current?.requester === "object"
421420
? {
422-
requester: this.LavalinkManager.utils.getTransformedRequester(
423-
this.queue.current?.requester || {},
424-
),
425-
}
421+
requester: this.LavalinkManager.utils.getTransformedRequester(
422+
this.queue.current?.requester || {},
423+
),
424+
}
426425
: {}),
427426
...options?.track?.userData,
428427
...this.queue.current?.userData,
@@ -484,7 +483,7 @@ export class Player {
484483
/**
485484
* The old JSON of the player, used for the "playerClientUpdate" event, which is emitted on every update of the player via a function call, so that you can compare the old data with the new data and do something with it if you want to.
486485
*/
487-
public oldJSON:PlayerJson = this.toJSON();
486+
public oldJSON: PlayerJson = this.toJSON();
488487

489488
/**
490489
* Emits the "playerClientUpdate" event, which is emitted on every update of the player via a function call, so that you can compare the old data with the new data and do something with it if you want to.
@@ -969,7 +968,9 @@ export class Player {
969968
functionLayer: "Player > changeNode()",
970969
});
971970
});
972-
} else if (this.LavalinkManager.options?.playerOptions?.enforceSponsorBlockRequestForEventEnablement !== false) {
971+
} else if (
972+
this.LavalinkManager.options?.playerOptions?.enforceSponsorBlockRequestForEventEnablement !== false
973+
) {
973974
// Even without user-set categories, we must call setSponsorBlock() with defaults
974975
// so the SponsorBlock plugin registers its event listeners (ChapterStarted/ChapterLoaded) on the new node.
975976
await this.setSponsorBlock().catch((error) => {

0 commit comments

Comments
 (0)