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.
Files changed (32) hide show
  1. package/README.md +76 -1
  2. package/dist/cjs/structures/Filters.d.ts +1 -1
  3. package/dist/cjs/structures/Filters.js +5 -5
  4. package/dist/cjs/structures/LavalinkManager.d.ts +18 -1
  5. package/dist/cjs/structures/LavalinkManager.js +14 -1
  6. package/dist/cjs/structures/LavalinkManagerStatics.d.ts +3 -0
  7. package/dist/cjs/structures/LavalinkManagerStatics.js +3 -0
  8. package/dist/cjs/structures/Node.d.ts +307 -22
  9. package/dist/cjs/structures/Node.js +317 -68
  10. package/dist/cjs/structures/Player.d.ts +44 -8
  11. package/dist/cjs/structures/Player.js +26 -18
  12. package/dist/cjs/structures/Utils.d.ts +3 -0
  13. package/dist/cjs/structures/Utils.js +1 -0
  14. package/dist/esm/structures/Filters.d.ts +1 -1
  15. package/dist/esm/structures/Filters.js +5 -5
  16. package/dist/esm/structures/LavalinkManager.d.ts +18 -1
  17. package/dist/esm/structures/LavalinkManager.js +14 -1
  18. package/dist/esm/structures/LavalinkManagerStatics.d.ts +3 -0
  19. package/dist/esm/structures/LavalinkManagerStatics.js +3 -0
  20. package/dist/esm/structures/Node.d.ts +307 -22
  21. package/dist/esm/structures/Node.js +317 -68
  22. package/dist/esm/structures/Player.d.ts +44 -8
  23. package/dist/esm/structures/Player.js +26 -18
  24. package/dist/esm/structures/Utils.d.ts +3 -0
  25. package/dist/esm/structures/Utils.js +1 -0
  26. package/dist/types/structures/Filters.d.ts +1 -1
  27. package/dist/types/structures/LavalinkManager.d.ts +18 -1
  28. package/dist/types/structures/LavalinkManagerStatics.d.ts +3 -0
  29. package/dist/types/structures/Node.d.ts +307 -22
  30. package/dist/types/structures/Player.d.ts +44 -8
  31. package/dist/types/structures/Utils.d.ts +3 -0
  32. package/package.json +2 -3
@@ -4,28 +4,58 @@ import { LavalinkNode, SponsorBlockSegment } from "./Node";
4
4
  import { Queue } from "./Queue";
5
5
  import { Track, UnresolvedTrack } from "./Track";
6
6
  import { Base64, LavalinkPlayerVoiceOptions, LavaSearchQuery, SearchQuery } from "./Utils";
7
- type PlayerDestroyReasons = "QueueEmpty" | "NodeDestroy" | "NodeDeleted" | "LavalinkNoVoice" | "NodeReconnectFail" | "PlayerReconnectFail" | "Disconnected" | "ChannelDeleted" | "ReconnectAllNodes" | "DisconnectAllNodes";
8
- export type DestroyReasonsType = PlayerDestroyReasons | string;
9
- export declare const DestroyReasons: Record<PlayerDestroyReasons, PlayerDestroyReasons>;
7
+ export declare enum DestroyReasons {
8
+ QueueEmpty = "QueueEmpty",
9
+ NodeDestroy = "NodeDestroy",
10
+ NodeDeleted = "NodeDeleted",
11
+ LavalinkNoVoice = "LavalinkNoVoice",
12
+ NodeReconnectFail = "NodeReconnectFail",
13
+ Disconnected = "Disconnected",
14
+ PlayerReconnectFail = "PlayerReconnectFail",
15
+ ChannelDeleted = "ChannelDeleted",
16
+ DisconnectAllNodes = "DisconnectAllNodes",
17
+ ReconnectAllNodes = "ReconnectAllNodes"
18
+ }
19
+ export type DestroyReasonsType = keyof typeof DestroyReasons | string;
10
20
  export interface PlayerJson {
21
+ /** Guild Id where the player was playing in */
11
22
  guildId: string;
23
+ /** Options provided to the player */
12
24
  options: PlayerOptions;
25
+ /** Voice Channel Id the player was playing in */
13
26
  voiceChannelId: string;
27
+ /** Text Channel Id the player was synced to */
14
28
  textChannelId?: string;
29
+ /** Position the player was at */
15
30
  position: number;
31
+ /** Lavalink's position the player was at */
16
32
  lastPosition: number;
33
+ /** Last time the position was sent from lavalink */
34
+ lastPositionChange: number;
35
+ /** Volume in % from the player (without volumeDecrementer) */
17
36
  volume: number;
37
+ /** Real Volume used in lavalink (with the volumeDecrementer) */
18
38
  lavalinkVolume: number;
39
+ /** The repeatmode from the player */
19
40
  repeatMode: RepeatMode;
41
+ /** Pause state */
20
42
  paused: boolean;
43
+ /** Wether the player was playing or not */
21
44
  playing: boolean;
45
+ /** When the player was created */
22
46
  createdTimeStamp?: number;
47
+ /** All current used fitlers Data */
23
48
  filters: FilterData;
49
+ /** The player's ping object */
24
50
  ping: {
51
+ /** Ping to the voice websocket server */
25
52
  ws: number;
53
+ /** Avg. calc. Ping to the lavalink server */
26
54
  lavalink: number;
27
55
  };
56
+ /** Equalizer Bands used in lavalink */
28
57
  equalizer: EQBand[];
58
+ /** The Id of the last used node */
29
59
  nodeId?: string;
30
60
  }
31
61
  export type RepeatMode = "queue" | "track" | "off";
@@ -88,10 +118,15 @@ export interface PlayOptions extends LavalinkPlayOptions {
88
118
  clientTrack?: Track | UnresolvedTrack;
89
119
  }
90
120
  export interface Player {
121
+ /** Filter Manager per player */
91
122
  filterManager: FilterManager;
123
+ /** circular reference to the lavalink Manager from the Player for easier use */
92
124
  LavalinkManager: LavalinkManager;
125
+ /** Player options currently used, mutation doesn't affect player's state */
93
126
  options: PlayerOptions;
127
+ /** The lavalink node assigned the the player, don't change it manually */
94
128
  node: LavalinkNode;
129
+ /** The queue from the player */
95
130
  queue: Queue;
96
131
  }
97
132
  export declare class Player {
@@ -117,7 +152,9 @@ export declare class Player {
117
152
  /** The Volume Lavalink actually is outputting */
118
153
  lavalinkVolume: number;
119
154
  /** The current Positin of the player (Calculated) */
120
- position: number;
155
+ get position(): number;
156
+ /** The timestamp when the last position change update happened */
157
+ lastPositionChange: number;
121
158
  /** The current Positin of the player (from Lavalink) */
122
159
  lastPosition: number;
123
160
  /** When the player was created [Timestamp in Ms] (from lavalink) */
@@ -163,7 +200,7 @@ export declare class Player {
163
200
  * @param ignoreVolumeDecrementer If it should ignore the volumedecrementer option
164
201
  */
165
202
  setVolume(volume: number, ignoreVolumeDecrementer?: boolean): Promise<this>;
166
- lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<import("./Utils").SearchResult | import("./Utils").LavaSearchResponse>;
203
+ lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Utils").SearchResult | import("./Utils").LavaSearchResponse>;
167
204
  setSponsorBlock(segments?: SponsorBlockSegment[]): Promise<void>;
168
205
  getSponsorBlock(): Promise<SponsorBlockSegment[]>;
169
206
  deleteSponsorBlock(): Promise<void>;
@@ -172,7 +209,7 @@ export declare class Player {
172
209
  * @param query Query for your data
173
210
  * @param requestUser
174
211
  */
175
- search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
212
+ search(query: SearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
176
213
  /**
177
214
  * Pause the player
178
215
  */
@@ -220,7 +257,7 @@ export declare class Player {
220
257
  /**
221
258
  * Destroy the player and disconnect from the voice channel
222
259
  */
223
- destroy(reason?: string, disconnect?: boolean): Promise<this>;
260
+ destroy(reason?: DestroyReasons | string, disconnect?: boolean): Promise<this>;
224
261
  /**
225
262
  * Move the player on a different Audio-Node
226
263
  * @param newNode New Node / New Node Id
@@ -229,4 +266,3 @@ export declare class Player {
229
266
  /** Converts the Player including Queue to a Json state */
230
267
  toJSON(): PlayerJson;
231
268
  }
232
- export {};
@@ -2,18 +2,20 @@ import { bandCampSearch } from "./CustomSearches/BandCampSearch";
2
2
  import { FilterManager } from "./Filters";
3
3
  import { Queue, QueueSaver } from "./Queue";
4
4
  import { queueTrackEnd } from "./Utils";
5
- export const DestroyReasons = {
6
- QueueEmpty: "QueueEmpty",
7
- NodeDestroy: "NodeDestroy",
8
- NodeDeleted: "NodeDeleted",
9
- LavalinkNoVoice: "LavalinkNoVoice",
10
- NodeReconnectFail: "NodeReconnectFail",
11
- Disconnected: "Disconnected",
12
- PlayerReconnectFail: "PlayerReconnectFail",
13
- ChannelDeleted: "ChannelDeleted",
14
- DisconnectAllNodes: "DisconnectAllNodes",
15
- ReconnectAllNodes: "ReconnectAllNodes"
16
- };
5
+ export var DestroyReasons;
6
+ (function (DestroyReasons) {
7
+ DestroyReasons["QueueEmpty"] = "QueueEmpty";
8
+ DestroyReasons["NodeDestroy"] = "NodeDestroy";
9
+ DestroyReasons["NodeDeleted"] = "NodeDeleted";
10
+ DestroyReasons["LavalinkNoVoice"] = "LavalinkNoVoice";
11
+ DestroyReasons["NodeReconnectFail"] = "NodeReconnectFail";
12
+ DestroyReasons["Disconnected"] = "Disconnected";
13
+ DestroyReasons["PlayerReconnectFail"] = "PlayerReconnectFail";
14
+ DestroyReasons["ChannelDeleted"] = "ChannelDeleted";
15
+ DestroyReasons["DisconnectAllNodes"] = "DisconnectAllNodes";
16
+ DestroyReasons["ReconnectAllNodes"] = "ReconnectAllNodes";
17
+ })(DestroyReasons || (DestroyReasons = {}));
18
+ ;
17
19
  export class Player {
18
20
  /** The Guild Id of the Player */
19
21
  guildId;
@@ -39,7 +41,11 @@ export class Player {
39
41
  /** The Volume Lavalink actually is outputting */
40
42
  lavalinkVolume = 100;
41
43
  /** The current Positin of the player (Calculated) */
42
- position = 0;
44
+ get position() {
45
+ return this.lastPosition + (this.lastPositionChange ? Date.now() - this.lastPositionChange : 0);
46
+ }
47
+ /** The timestamp when the last position change update happened */
48
+ lastPositionChange = null;
43
49
  /** The current Positin of the player (from Lavalink) */
44
50
  lastPosition = 0;
45
51
  /** When the player was created [Timestamp in Ms] (from lavalink) */
@@ -242,8 +248,8 @@ export class Player {
242
248
  this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
243
249
  return this;
244
250
  }
245
- async lavaSearch(query, requestUser) {
246
- return this.node.lavaSearch(query, requestUser);
251
+ async lavaSearch(query, requestUser, throwOnEmpty = false) {
252
+ return this.node.lavaSearch(query, requestUser, throwOnEmpty);
247
253
  }
248
254
  async setSponsorBlock(segments = ["sponsor", "selfpromo"]) {
249
255
  return this.node.setSponsorBlock(this, segments);
@@ -259,11 +265,11 @@ export class Player {
259
265
  * @param query Query for your data
260
266
  * @param requestUser
261
267
  */
262
- async search(query, requestUser) {
268
+ async search(query, requestUser, throwOnEmpty = false) {
263
269
  const Query = this.LavalinkManager.utils.transformQuery(query);
264
270
  if (["bcsearch", "bandcamp"].includes(Query.source) && !this.node.info.sourceManagers.includes("bandcamp"))
265
271
  return await bandCampSearch(this, Query.query, requestUser);
266
- return this.node.search(Query, requestUser);
272
+ return this.node.search(Query, requestUser, throwOnEmpty);
267
273
  }
268
274
  /**
269
275
  * Pause the player
@@ -303,7 +309,7 @@ export class Player {
303
309
  throw new RangeError("Current Track is not seekable / a stream");
304
310
  if (position < 0 || position > this.queue.current.info.duration)
305
311
  position = Math.max(Math.min(position, this.queue.current.info.duration), 0);
306
- this.position = position;
312
+ this.lastPositionChange = Date.now();
307
313
  this.lastPosition = position;
308
314
  const now = performance.now();
309
315
  await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { position } });
@@ -485,6 +491,7 @@ export class Player {
485
491
  textChannelId: this.textChannelId,
486
492
  position: this.position,
487
493
  lastPosition: this.lastPosition,
494
+ lastPositionChange: this.lastPositionChange,
488
495
  volume: this.volume,
489
496
  lavalinkVolume: this.lavalinkVolume,
490
497
  repeatMode: this.repeatMode,
@@ -495,6 +502,7 @@ export class Player {
495
502
  equalizer: this.filterManager?.equalizerBands || [],
496
503
  nodeId: this.node?.id,
497
504
  ping: this.ping,
505
+ queue: this.queue.utils.toJSON(),
498
506
  };
499
507
  }
500
508
  }
@@ -105,6 +105,7 @@ export declare class ManagerUtils {
105
105
  validateQueryString(node: LavalinkNode, queryString: string, sourceString?: LavalinkSearchPlatform): void;
106
106
  transformQuery(query: SearchQuery): {
107
107
  query: string;
108
+ extraQueryUrlParams: URLSearchParams;
108
109
  source: any;
109
110
  };
110
111
  transformLavaSearchQuery(query: LavaSearchQuery): {
@@ -453,6 +454,8 @@ export interface LavaSearchResponse {
453
454
  export type SearchQuery = {
454
455
  /** lavalink search Query / identifier string */
455
456
  query: string;
457
+ /** Extra url query params to use, e.g. for flowertts */
458
+ extraQueryUrlParams?: URLSearchParams;
456
459
  /** Source to append to the search query string */
457
460
  source?: SearchPlatform;
458
461
  } | /** Our just the search query / identifier string */ string;
@@ -237,6 +237,7 @@ export class ManagerUtils {
237
237
  const sourceOfQuery = typeof query === "string" ? undefined : (DefaultSources[(query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()] ?? (query.source?.trim?.()?.toLowerCase?.()));
238
238
  const Query = {
239
239
  query: typeof query === "string" ? query : query.query,
240
+ extraQueryUrlParams: typeof query !== "string" ? query.extraQueryUrlParams : undefined,
240
241
  source: sourceOfQuery ?? this.LavalinkManager?.options?.playerOptions?.defaultSearchPlatform?.toLowerCase?.()
241
242
  };
242
243
  const foundSource = Object.keys(DefaultSources).find(source => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
@@ -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: number;
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.) */
@@ -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", () => {
@@ -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>;