lavalink-client 2.2.2 → 2.3.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 (111) hide show
  1. package/README.md +95 -1
  2. package/dist/cjs/index.d.ts +8 -1
  3. package/dist/cjs/index.js +8 -1
  4. package/dist/cjs/structures/Constants.d.ts +40 -0
  5. package/dist/cjs/structures/Constants.js +244 -0
  6. package/dist/cjs/structures/CustomSearches/BandCampSearch.d.ts +2 -2
  7. package/dist/cjs/structures/Filters.d.ts +2 -217
  8. package/dist/cjs/structures/Filters.js +8 -232
  9. package/dist/cjs/structures/LavalinkManager.d.ts +31 -166
  10. package/dist/cjs/structures/LavalinkManager.js +59 -7
  11. package/dist/cjs/structures/LavalinkManagerStatics.d.ts +1 -1
  12. package/dist/cjs/structures/Node.d.ts +15 -156
  13. package/dist/cjs/structures/Node.js +131 -49
  14. package/dist/cjs/structures/NodeManager.d.ts +54 -52
  15. package/dist/cjs/structures/NodeManager.js +74 -4
  16. package/dist/cjs/structures/Player.d.ts +31 -124
  17. package/dist/cjs/structures/Player.js +77 -43
  18. package/dist/cjs/structures/Queue.d.ts +66 -42
  19. package/dist/cjs/structures/Queue.js +69 -11
  20. package/dist/cjs/structures/Types/Filters.d.ts +190 -0
  21. package/dist/cjs/structures/Types/Manager.d.ts +184 -0
  22. package/dist/cjs/structures/Types/Manager.js +2 -0
  23. package/dist/cjs/structures/Types/Node.d.ts +216 -0
  24. package/dist/cjs/structures/Types/Node.js +2 -0
  25. package/dist/cjs/structures/Types/Player.d.ts +108 -0
  26. package/dist/cjs/structures/Types/Player.js +2 -0
  27. package/dist/cjs/structures/Types/Queue.d.ts +34 -0
  28. package/dist/cjs/structures/Types/Queue.js +2 -0
  29. package/dist/cjs/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
  30. package/dist/{structures → cjs/structures/Types}/Track.js +2 -2
  31. package/dist/cjs/structures/Types/Utils.d.ts +367 -0
  32. package/dist/cjs/structures/Types/Utils.js +2 -0
  33. package/dist/cjs/structures/Utils.d.ts +13 -369
  34. package/dist/cjs/structures/Utils.js +35 -14
  35. package/dist/esm/index.d.ts +8 -1
  36. package/dist/esm/index.js +8 -1
  37. package/dist/esm/structures/Constants.d.ts +40 -0
  38. package/dist/esm/structures/Constants.js +241 -0
  39. package/dist/esm/structures/CustomSearches/BandCampSearch.d.ts +2 -2
  40. package/dist/esm/structures/Filters.d.ts +2 -217
  41. package/dist/esm/structures/Filters.js +3 -227
  42. package/dist/esm/structures/LavalinkManager.d.ts +31 -166
  43. package/dist/esm/structures/LavalinkManager.js +57 -5
  44. package/dist/esm/structures/LavalinkManagerStatics.d.ts +1 -1
  45. package/dist/esm/structures/Node.d.ts +15 -156
  46. package/dist/esm/structures/Node.js +122 -40
  47. package/dist/esm/structures/NodeManager.d.ts +54 -52
  48. package/dist/esm/structures/NodeManager.js +71 -1
  49. package/dist/esm/structures/Player.d.ts +31 -124
  50. package/dist/esm/structures/Player.js +76 -42
  51. package/dist/esm/structures/Queue.d.ts +66 -42
  52. package/dist/esm/structures/Queue.js +69 -11
  53. package/dist/esm/structures/Types/Filters.d.ts +190 -0
  54. package/dist/esm/structures/Types/Manager.d.ts +184 -0
  55. package/dist/esm/structures/Types/Manager.js +1 -0
  56. package/dist/esm/structures/Types/Node.d.ts +216 -0
  57. package/dist/esm/structures/Types/Node.js +1 -0
  58. package/dist/esm/structures/Types/Player.d.ts +108 -0
  59. package/dist/esm/structures/Types/Player.js +1 -0
  60. package/dist/esm/structures/Types/Queue.d.ts +34 -0
  61. package/dist/esm/structures/Types/Queue.js +1 -0
  62. package/dist/esm/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
  63. package/dist/esm/structures/Types/Track.js +1 -0
  64. package/dist/esm/structures/Types/Utils.d.ts +367 -0
  65. package/dist/esm/structures/Types/Utils.js +1 -0
  66. package/dist/esm/structures/Utils.d.ts +13 -369
  67. package/dist/esm/structures/Utils.js +35 -14
  68. package/dist/types/index.d.ts +8 -1
  69. package/dist/types/structures/Constants.d.ts +40 -0
  70. package/dist/types/structures/CustomSearches/BandCampSearch.d.ts +2 -2
  71. package/dist/types/structures/Filters.d.ts +2 -217
  72. package/dist/types/structures/LavalinkManager.d.ts +31 -166
  73. package/dist/types/structures/LavalinkManagerStatics.d.ts +1 -1
  74. package/dist/types/structures/Node.d.ts +15 -156
  75. package/dist/types/structures/NodeManager.d.ts +54 -52
  76. package/dist/types/structures/Player.d.ts +31 -124
  77. package/dist/types/structures/Queue.d.ts +66 -42
  78. package/dist/types/structures/Types/Filters.d.ts +190 -0
  79. package/dist/types/structures/Types/Manager.d.ts +184 -0
  80. package/dist/types/structures/Types/Node.d.ts +216 -0
  81. package/dist/types/structures/Types/Player.d.ts +108 -0
  82. package/dist/types/structures/Types/Queue.d.ts +34 -0
  83. package/dist/types/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
  84. package/dist/types/structures/Types/Utils.d.ts +367 -0
  85. package/dist/types/structures/Utils.d.ts +13 -369
  86. package/package.json +1 -1
  87. package/dist/index.d.ts +0 -10
  88. package/dist/index.js +0 -13
  89. package/dist/structures/Filters.d.ts +0 -230
  90. package/dist/structures/Filters.js +0 -472
  91. package/dist/structures/LavalinkManager.d.ts +0 -47
  92. package/dist/structures/LavalinkManager.js +0 -36
  93. package/dist/structures/LavalinkManagerStatics.d.ts +0 -3
  94. package/dist/structures/LavalinkManagerStatics.js +0 -76
  95. package/dist/structures/Node.d.ts +0 -171
  96. package/dist/structures/Node.js +0 -462
  97. package/dist/structures/NodeManager.d.ts +0 -58
  98. package/dist/structures/NodeManager.js +0 -25
  99. package/dist/structures/Player.d.ts +0 -101
  100. package/dist/structures/Player.js +0 -232
  101. package/dist/structures/PlayerManager.d.ts +0 -62
  102. package/dist/structures/PlayerManager.js +0 -26
  103. package/dist/structures/Queue.d.ts +0 -93
  104. package/dist/structures/Queue.js +0 -160
  105. package/dist/structures/QueueManager.d.ts +0 -77
  106. package/dist/structures/QueueManager.js +0 -74
  107. package/dist/structures/Track.d.ts +0 -27
  108. package/dist/structures/Utils.d.ts +0 -183
  109. package/dist/structures/Utils.js +0 -43
  110. /package/dist/cjs/structures/{Track.js → Types/Filters.js} +0 -0
  111. /package/dist/esm/structures/{Track.js → Types/Filters.js} +0 -0
@@ -1,68 +1,56 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "stream";
3
- import { LavalinkManager } from "./LavalinkManager";
4
- import { LavalinkNode, LavalinkNodeOptions } from "./Node";
5
- import { DestroyReasonsType } from "./Player";
6
- import { LavalinkPlayer, MiniMap } from "./Utils";
7
- type LavalinkNodeIdentifier = string;
8
- export interface NodeManagerEvents {
3
+ import { LavalinkNode } from "./Node";
4
+ import { MiniMap } from "./Utils";
5
+ import type { LavalinkNodeIdentifier, LavalinkNodeOptions, NodeManagerEvents } from "./Types/Node";
6
+ import type { LavalinkManager } from "./LavalinkManager";
7
+ export declare class NodeManager extends EventEmitter {
9
8
  /**
10
- * Emitted when a Node is created.
11
- * @event Manager.nodeManager#create
9
+ * Emit an event
10
+ * @param event The event to emit
11
+ * @param args The arguments to pass to the event
12
+ * @returns
12
13
  */
13
- "create": (node: LavalinkNode) => void;
14
+ emit<Event extends keyof NodeManagerEvents>(event: Event, ...args: Parameters<NodeManagerEvents[Event]>): boolean;
14
15
  /**
15
- * Emitted when a Node is destroyed.
16
- * @event Manager.nodeManager#destroy
16
+ * Add an event listener
17
+ * @param event The event to listen to
18
+ * @param listener The listener to add
19
+ * @returns
17
20
  */
18
- "destroy": (node: LavalinkNode, destroyReason?: DestroyReasonsType) => void;
21
+ on<Event extends keyof NodeManagerEvents>(event: Event, listener: NodeManagerEvents[Event]): this;
19
22
  /**
20
- * Emitted when a Node is connected.
21
- * @event Manager.nodeManager#connect
23
+ * Add an event listener that only fires once
24
+ * @param event The event to listen to
25
+ * @param listener The listener to add
26
+ * @returns
22
27
  */
23
- "connect": (node: LavalinkNode) => void;
24
- /**
25
- * Emitted when a Node is reconnecting.
26
- * @event Manager.nodeManager#reconnecting
27
- */
28
- "reconnecting": (node: LavalinkNode) => void;
29
- /**
30
- * Emitted when a Node is disconnects.
31
- * @event Manager.nodeManager#disconnect
32
- */
33
- "disconnect": (node: LavalinkNode, reason: {
34
- code?: number;
35
- reason?: string;
36
- }) => void;
28
+ once<Event extends keyof NodeManagerEvents>(event: Event, listener: NodeManagerEvents[Event]): this;
37
29
  /**
38
- * Emitted when a Node is error.
39
- * @event Manager.nodeManager#error
40
- */
41
- "error": (node: LavalinkNode, error: Error, payload?: unknown) => void;
30
+ * Remove an event listener
31
+ * @param event The event to remove the listener from
32
+ * @param listener The listener to remove
33
+ * @returns
34
+ */
35
+ off<Event extends keyof NodeManagerEvents>(event: Event, listener: NodeManagerEvents[Event]): this;
42
36
  /**
43
- * Emits every single Node event.
44
- * @event Manager.nodeManager#raw
45
- */
46
- "raw": (node: LavalinkNode, payload: unknown) => void;
37
+ * Remove an event listener
38
+ * @param event The event to remove the listener from
39
+ * @param listener The listener to remove
40
+ * @returns
41
+ */
42
+ removeListener<Event extends keyof NodeManagerEvents>(event: Event, listener: NodeManagerEvents[Event]): this;
47
43
  /**
48
- * Emits when the node connects resumed. You then need to create all players within this event for your usecase.
49
- * Aka for that you need to be able to save player data like vc channel + text channel in a db and then sync it again
50
- * @event Manager.nodeManager#nodeResumed
44
+ * The LavalinkManager that created this NodeManager
51
45
  */
52
- "resumed": (node: LavalinkNode, paylaod: {
53
- resumed: true;
54
- sessionId: string;
55
- op: "ready";
56
- }, players: LavalinkPlayer[]) => void;
57
- }
58
- export declare interface NodeManager {
59
- on<U extends keyof NodeManagerEvents>(event: U, listener: NodeManagerEvents[U]): this;
60
- emit<U extends keyof NodeManagerEvents>(event: U, ...args: Parameters<NodeManagerEvents[U]>): boolean;
61
- /** @private */
62
46
  LavalinkManager: LavalinkManager;
63
- }
64
- export declare class NodeManager extends EventEmitter {
47
+ /**
48
+ * A map of all nodes in the nodeManager
49
+ */
65
50
  nodes: MiniMap<string, LavalinkNode>;
51
+ /**
52
+ * @param LavalinkManager The LavalinkManager that created this NodeManager
53
+ */
66
54
  constructor(LavalinkManager: LavalinkManager);
67
55
  /**
68
56
  * Disconnects all Nodes from lavalink ws sockets
@@ -80,8 +68,22 @@ export declare class NodeManager extends EventEmitter {
80
68
  * @returns amount of nodes
81
69
  */
82
70
  reconnectAll(): Promise<number>;
71
+ /**
72
+ * Create a node and add it to the nodeManager
73
+ * @param options The options for the node
74
+ * @returns The node that was created
75
+ */
83
76
  createNode(options: LavalinkNodeOptions): LavalinkNode;
77
+ /**
78
+ * Get the nodes sorted for the least usage, by a sorttype
79
+ * @param sortType The type of sorting to use
80
+ * @returns
81
+ */
84
82
  leastUsedNodes(sortType?: "memory" | "cpuLavalink" | "cpuSystem" | "calls" | "playingPlayers" | "players"): LavalinkNode[];
83
+ /**
84
+ * Delete a node from the nodeManager and destroy it
85
+ * @param node The node to delete
86
+ * @returns
87
+ */
85
88
  deleteNode(node: LavalinkNodeIdentifier | LavalinkNode): void;
86
89
  }
87
- export {};
@@ -2,11 +2,66 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeManager = void 0;
4
4
  const stream_1 = require("stream");
5
+ const Constants_1 = require("./Constants");
5
6
  const Node_1 = require("./Node");
6
- const Player_1 = require("./Player");
7
7
  const Utils_1 = require("./Utils");
8
8
  class NodeManager extends stream_1.EventEmitter {
9
+ /**
10
+ * Emit an event
11
+ * @param event The event to emit
12
+ * @param args The arguments to pass to the event
13
+ * @returns
14
+ */
15
+ emit(event, ...args) {
16
+ return super.emit(event, ...args);
17
+ }
18
+ /**
19
+ * Add an event listener
20
+ * @param event The event to listen to
21
+ * @param listener The listener to add
22
+ * @returns
23
+ */
24
+ on(event, listener) {
25
+ return super.on(event, listener);
26
+ }
27
+ /**
28
+ * Add an event listener that only fires once
29
+ * @param event The event to listen to
30
+ * @param listener The listener to add
31
+ * @returns
32
+ */
33
+ once(event, listener) {
34
+ return super.once(event, listener);
35
+ }
36
+ /**
37
+ * Remove an event listener
38
+ * @param event The event to remove the listener from
39
+ * @param listener The listener to remove
40
+ * @returns
41
+ */
42
+ off(event, listener) {
43
+ return super.off(event, listener);
44
+ }
45
+ /**
46
+ * Remove an event listener
47
+ * @param event The event to remove the listener from
48
+ * @param listener The listener to remove
49
+ * @returns
50
+ */
51
+ removeListener(event, listener) {
52
+ return super.removeListener(event, listener);
53
+ }
54
+ /**
55
+ * The LavalinkManager that created this NodeManager
56
+ */
57
+ LavalinkManager;
58
+ /**
59
+ * A map of all nodes in the nodeManager
60
+ */
9
61
  nodes = new Utils_1.MiniMap();
62
+ /**
63
+ * @param LavalinkManager The LavalinkManager that created this NodeManager
64
+ */
10
65
  constructor(LavalinkManager) {
11
66
  super();
12
67
  this.LavalinkManager = LavalinkManager;
@@ -29,7 +84,7 @@ class NodeManager extends stream_1.EventEmitter {
29
84
  for (const node of [...this.nodes.values()]) {
30
85
  if (!node.connected)
31
86
  continue;
32
- await node.destroy(Player_1.DestroyReasons.DisconnectAllNodes, deleteAllNodes);
87
+ await node.destroy(Constants_1.DestroyReasons.DisconnectAllNodes, deleteAllNodes);
33
88
  counter++;
34
89
  }
35
90
  return counter;
@@ -62,12 +117,17 @@ class NodeManager extends stream_1.EventEmitter {
62
117
  let counter = 0;
63
118
  for (const node of [...this.nodes.values()]) {
64
119
  const sessionId = node.sessionId ? `${node.sessionId}` : undefined;
65
- await node.destroy(Player_1.DestroyReasons.ReconnectAllNodes, false);
120
+ await node.destroy(Constants_1.DestroyReasons.ReconnectAllNodes, false);
66
121
  await node.connect(sessionId);
67
122
  counter++;
68
123
  }
69
124
  return counter;
70
125
  }
126
+ /**
127
+ * Create a node and add it to the nodeManager
128
+ * @param options The options for the node
129
+ * @returns The node that was created
130
+ */
71
131
  createNode(options) {
72
132
  if (this.nodes.has(options.id || `${options.host}:${options.port}`))
73
133
  return this.nodes.get(options.id || `${options.host}:${options.port}`);
@@ -75,6 +135,11 @@ class NodeManager extends stream_1.EventEmitter {
75
135
  this.nodes.set(newNode.id, newNode);
76
136
  return newNode;
77
137
  }
138
+ /**
139
+ * Get the nodes sorted for the least usage, by a sorttype
140
+ * @param sortType The type of sorting to use
141
+ * @returns
142
+ */
78
143
  leastUsedNodes(sortType = "players") {
79
144
  switch (sortType) {
80
145
  case "memory":
@@ -128,11 +193,16 @@ class NodeManager extends stream_1.EventEmitter {
128
193
  break;
129
194
  }
130
195
  }
196
+ /**
197
+ * Delete a node from the nodeManager and destroy it
198
+ * @param node The node to delete
199
+ * @returns
200
+ */
131
201
  deleteNode(node) {
132
202
  const decodeNode = typeof node === "string" ? this.nodes.get(node) : node || this.leastUsedNodes()[0];
133
203
  if (!decodeNode)
134
204
  throw new Error("Node was not found");
135
- decodeNode.destroy(Player_1.DestroyReasons.NodeDeleted);
205
+ decodeNode.destroy(Constants_1.DestroyReasons.NodeDeleted);
136
206
  this.nodes.delete(decodeNode.id);
137
207
  return;
138
208
  }
@@ -1,123 +1,12 @@
1
- import { EQBand, FilterData, FilterManager, LavalinkFilterData } from "./Filters";
2
- import { LavalinkManager } from "./LavalinkManager";
3
- import { LavalinkNode, SponsorBlockSegment } from "./Node";
1
+ import { FilterManager } from "./Filters";
4
2
  import { Queue } from "./Queue";
5
- import { Track, UnresolvedTrack } from "./Track";
6
- import { Base64, LavalinkPlayerVoiceOptions, LavaSearchQuery, SearchQuery } from "./Utils";
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;
20
- export interface PlayerJson {
21
- /** Guild Id where the player was playing in */
22
- guildId: string;
23
- /** Options provided to the player */
24
- options: PlayerOptions;
25
- /** Voice Channel Id the player was playing in */
26
- voiceChannelId: string;
27
- /** Text Channel Id the player was synced to */
28
- textChannelId?: string;
29
- /** Position the player was at */
30
- position: number;
31
- /** Lavalink's position the player was at */
32
- lastPosition: number;
33
- /** Last time the position was sent from lavalink */
34
- lastPositionChange: number;
35
- /** Volume in % from the player (without volumeDecrementer) */
36
- volume: number;
37
- /** Real Volume used in lavalink (with the volumeDecrementer) */
38
- lavalinkVolume: number;
39
- /** The repeatmode from the player */
40
- repeatMode: RepeatMode;
41
- /** Pause state */
42
- paused: boolean;
43
- /** Wether the player was playing or not */
44
- playing: boolean;
45
- /** When the player was created */
46
- createdTimeStamp?: number;
47
- /** All current used fitlers Data */
48
- filters: FilterData;
49
- /** The player's ping object */
50
- ping: {
51
- /** Ping to the voice websocket server */
52
- ws: number;
53
- /** Avg. calc. Ping to the lavalink server */
54
- lavalink: number;
55
- };
56
- /** Equalizer Bands used in lavalink */
57
- equalizer: EQBand[];
58
- /** The Id of the last used node */
59
- nodeId?: string;
60
- }
61
- export type RepeatMode = "queue" | "track" | "off";
62
- export interface PlayerOptions {
63
- /** Guild id of the player */
64
- guildId: string;
65
- /** The Voice Channel Id */
66
- voiceChannelId: string;
67
- /** The Text Channel Id of the Player */
68
- textChannelId?: string;
69
- /** instantly change volume with the one play request */
70
- volume?: number;
71
- /** VC Region for node selections */
72
- vcRegion?: string;
73
- /** if it should join deafened */
74
- selfDeaf?: boolean;
75
- /** If it should join muted */
76
- selfMute?: boolean;
77
- /** If it should use a specific lavalink node */
78
- node?: LavalinkNode | string;
79
- /** If when applying filters, it should use the insta apply filters fix */
80
- instaUpdateFiltersFix?: boolean;
81
- /** If a volume should be applied via filters instead of lavalink-volume */
82
- applyVolumeAsFilter?: boolean;
83
- }
84
- export type anyObject = {
85
- [key: string | number]: string | number | null | anyObject;
86
- };
87
- export interface BasePlayOptions {
88
- /** The position to start the track. */
89
- position?: number;
90
- /** The position to end the track. */
91
- endTime?: number;
92
- /** If to start "paused" */
93
- paused?: boolean;
94
- /** The Volume to start with */
95
- volume?: number;
96
- /** The Lavalink Filters to use | only with the new REST API */
97
- filters?: Partial<LavalinkFilterData>;
98
- /** Voice Update for Lavalink */
99
- voice?: LavalinkPlayerVoiceOptions;
100
- }
101
- export interface LavalinkPlayOptions extends BasePlayOptions {
102
- /** Which Track to play | don't provide, if it should pick from the Queue */
103
- track?: {
104
- /** The track encoded base64 string to use instead of the one from the queue system */
105
- encoded?: Base64 | null;
106
- /** The identifier of the track to use */
107
- identifier?: string;
108
- /** Custom User Data for the track to provide, will then be on the userData object from the track */
109
- userData?: anyObject;
110
- /** The Track requester for when u provide encodedTrack / identifer */
111
- requester?: unknown;
112
- };
113
- }
114
- export interface PlayOptions extends LavalinkPlayOptions {
115
- /** Whether to not replace the track if a play payload is sent. */
116
- noReplace?: boolean;
117
- /** Adds track on queue and skips to it */
118
- clientTrack?: Track | UnresolvedTrack;
119
- }
120
- export interface Player {
3
+ import type { DestroyReasons } from "./Constants";
4
+ import type { LavalinkNode } from "./Node";
5
+ import type { SponsorBlockSegment } from "./Types/Node";
6
+ import type { PlayerJson, PlayerOptions, PlayOptions, RepeatMode } from "./Types/Player";
7
+ import type { LavalinkManager } from "./LavalinkManager";
8
+ import type { LavalinkPlayerVoiceOptions, LavaSearchQuery, SearchQuery } from "./Types/Utils";
9
+ export declare class Player {
121
10
  /** Filter Manager per player */
122
11
  filterManager: FilterManager;
123
12
  /** circular reference to the lavalink Manager from the Player for easier use */
@@ -128,8 +17,6 @@ export interface Player {
128
17
  node: LavalinkNode;
129
18
  /** The queue from the player */
130
19
  queue: Queue;
131
- }
132
- export declare class Player {
133
20
  /** The Guild Id of the Player */
134
21
  guildId: string;
135
22
  /** The Voice Channel Id of the Player */
@@ -157,12 +44,14 @@ export declare class Player {
157
44
  lastPositionChange: number;
158
45
  /** The current Positin of the player (from Lavalink) */
159
46
  lastPosition: number;
47
+ lastSavedPosition: number;
160
48
  /** When the player was created [Timestamp in Ms] (from lavalink) */
161
49
  createdTimeStamp: number;
162
50
  /** The Player Connection's State (from Lavalink) */
163
51
  connected: boolean | undefined;
164
52
  /** Voice Server Data (from Lavalink) */
165
53
  voice: LavalinkPlayerVoiceOptions;
54
+ /** Custom data for the player */
166
55
  private readonly data;
167
56
  /**
168
57
  * Create a new Player
@@ -200,16 +89,33 @@ export declare class Player {
200
89
  * @param ignoreVolumeDecrementer If it should ignore the volumedecrementer option
201
90
  */
202
91
  setVolume(volume: number, ignoreVolumeDecrementer?: boolean): Promise<this>;
203
- lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Utils").SearchResult | import("./Utils").LavaSearchResponse>;
92
+ /**
93
+ * Search for a track
94
+ * @param query The query to search for
95
+ * @param requestUser The user that requested the track
96
+ * @param throwOnEmpty If an error should be thrown if no track is found
97
+ * @returns The search result
98
+ */
99
+ lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Types/Utils").SearchResult | import("./Types/Utils").LavaSearchResponse>;
100
+ /**
101
+ * Set the SponsorBlock
102
+ * @param segments The segments to set
103
+ */
204
104
  setSponsorBlock(segments?: SponsorBlockSegment[]): Promise<void>;
105
+ /**
106
+ * Get the SponsorBlock
107
+ */
205
108
  getSponsorBlock(): Promise<SponsorBlockSegment[]>;
109
+ /**
110
+ * Delete the SponsorBlock
111
+ */
206
112
  deleteSponsorBlock(): Promise<void>;
207
113
  /**
208
114
  *
209
115
  * @param query Query for your data
210
116
  * @param requestUser
211
117
  */
212
- search(query: SearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
118
+ search(query: SearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<import("./Types/Utils").UnresolvedSearchResult | import("./Types/Utils").SearchResult>;
213
119
  /**
214
120
  * Pause the player
215
121
  */
@@ -228,11 +134,12 @@ export declare class Player {
228
134
  * @param repeatMode
229
135
  */
230
136
  setRepeatMode(repeatMode: RepeatMode): Promise<this>;
137
+ 1: any;
231
138
  /**
232
139
  * Skip the current song, or a specific amount of songs
233
140
  * @param amount provide the index of the next track to skip to
234
141
  */
235
- skip(skipTo?: number, throwError?: boolean): any;
142
+ skip(skipTo?: number, throwError?: boolean): Promise<this>;
236
143
  /**
237
144
  * Clears the queue and stops playing. Does not destroy the Player and not leave the channel
238
145
  * @returns
@@ -1,25 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Player = exports.DestroyReasons = void 0;
3
+ exports.Player = void 0;
4
4
  const BandCampSearch_1 = require("./CustomSearches/BandCampSearch");
5
5
  const Filters_1 = require("./Filters");
6
6
  const Queue_1 = require("./Queue");
7
7
  const Utils_1 = require("./Utils");
8
- var DestroyReasons;
9
- (function (DestroyReasons) {
10
- DestroyReasons["QueueEmpty"] = "QueueEmpty";
11
- DestroyReasons["NodeDestroy"] = "NodeDestroy";
12
- DestroyReasons["NodeDeleted"] = "NodeDeleted";
13
- DestroyReasons["LavalinkNoVoice"] = "LavalinkNoVoice";
14
- DestroyReasons["NodeReconnectFail"] = "NodeReconnectFail";
15
- DestroyReasons["Disconnected"] = "Disconnected";
16
- DestroyReasons["PlayerReconnectFail"] = "PlayerReconnectFail";
17
- DestroyReasons["ChannelDeleted"] = "ChannelDeleted";
18
- DestroyReasons["DisconnectAllNodes"] = "DisconnectAllNodes";
19
- DestroyReasons["ReconnectAllNodes"] = "ReconnectAllNodes";
20
- })(DestroyReasons || (exports.DestroyReasons = DestroyReasons = {}));
21
- ;
22
8
  class Player {
9
+ /** Filter Manager per player */
10
+ filterManager;
11
+ /** circular reference to the lavalink Manager from the Player for easier use */
12
+ LavalinkManager;
13
+ /** Player options currently used, mutation doesn't affect player's state */
14
+ options;
15
+ /** The lavalink node assigned the the player, don't change it manually */
16
+ node;
17
+ /** The queue from the player */
18
+ queue;
23
19
  /** The Guild Id of the Player */
24
20
  guildId;
25
21
  /** The Voice Channel Id of the Player */
@@ -51,6 +47,7 @@ class Player {
51
47
  lastPositionChange = null;
52
48
  /** The current Positin of the player (from Lavalink) */
53
49
  lastPosition = 0;
50
+ lastSavedPosition = 0;
54
51
  /** When the player was created [Timestamp in Ms] (from lavalink) */
55
52
  createdTimeStamp;
56
53
  /** The Player Connection's State (from Lavalink) */
@@ -61,6 +58,7 @@ class Player {
61
58
  sessionId: null,
62
59
  token: null
63
60
  };
61
+ /** Custom data for the player */
64
62
  data = {};
65
63
  /**
66
64
  * Create a new Player
@@ -133,39 +131,56 @@ class Player {
133
131
  clearTimeout(this.get("internal_queueempty"));
134
132
  this.set("internal_queueempty", undefined);
135
133
  }
136
- let replaced = false;
137
- // if clientTrack provided, play it
134
+ // if clientTrack provided, override options.track object
138
135
  if (options?.clientTrack && (this.LavalinkManager.utils.isTrack(options?.clientTrack) || this.LavalinkManager.utils.isUnresolvedTrack(options.clientTrack))) {
139
136
  if (this.LavalinkManager.utils.isUnresolvedTrack(options.clientTrack))
140
137
  await options.clientTrack.resolve(this);
141
138
  if ((typeof options.track?.userData === "object" || typeof options.clientTrack?.userData === "object") && options.clientTrack)
142
139
  options.clientTrack.userData = { ...(options?.clientTrack.userData || {}), ...(options.track?.userData || {}) };
143
- await this.queue.add(options?.clientTrack, 0);
144
- return await this.skip();
140
+ options.track = {
141
+ encoded: options.clientTrack?.encoded,
142
+ requester: options.clientTrack?.requester,
143
+ userData: options.clientTrack?.userData,
144
+ };
145
145
  }
146
- else if (options?.track?.encoded) {
147
- // handle play encoded options manually // TODO let it resolve by lavalink!
148
- const track = await this.node.decode.singleTrack(options.track?.encoded, options.track?.requester || this.queue?.current?.requester || this.queue.previous?.[0]?.requester || this.queue.tracks?.[0]?.requester || this.LavalinkManager.options.client);
149
- if (track) {
150
- if (typeof options.track?.userData === "object")
151
- track.userData = { ...(track.userData || {}), ...(options.track.userData || {}) };
152
- replaced = true;
153
- this.queue.add(track, 0);
154
- await (0, Utils_1.queueTrackEnd)(this);
155
- }
156
- }
157
- else if (options?.track?.identifier) {
158
- // handle play identifier options manually // TODO let it resolve by lavalink!
159
- const res = await this.search({
160
- query: options?.track?.identifier
161
- }, options?.track?.requester || this.queue?.current?.requester || this.queue.previous?.[0]?.requester || this.queue.tracks?.[0]?.requester || this.LavalinkManager.options.client);
162
- if (res.tracks[0]) {
163
- if (typeof options.track?.userData === "object")
164
- res.tracks[0].userData = { ...(res.tracks[0].userData || {}), ...(options.track.userData || {}) };
165
- replaced = true;
166
- this.queue.add(res.tracks[0], 0);
167
- await (0, Utils_1.queueTrackEnd)(this);
146
+ // if either encoded or identifier is provided generate the data to play them
147
+ if (options?.track?.encoded || options?.track?.identifier) {
148
+ this.queue.current = options.clientTrack || null;
149
+ this.queue.utils.save();
150
+ if (typeof options?.volume === "number" && !isNaN(options?.volume)) {
151
+ this.volume = Math.max(Math.min(options?.volume, 500), 0);
152
+ let vol = Number(this.volume);
153
+ if (this.LavalinkManager.options.playerOptions.volumeDecrementer)
154
+ vol *= this.LavalinkManager.options.playerOptions.volumeDecrementer;
155
+ this.lavalinkVolume = Math.round(vol);
156
+ options.volume = this.lavalinkVolume;
168
157
  }
158
+ const track = Object.fromEntries(Object.entries({
159
+ encoded: options.track.encoded,
160
+ identifier: options.track.identifier,
161
+ }).filter(v => typeof v[1] !== "undefined"));
162
+ if (typeof options.track.userData === "object")
163
+ track.userData = {
164
+ ...(options.track.userData || {})
165
+ };
166
+ if (typeof options?.track?.requester === "object")
167
+ track.userData = {
168
+ ...(track.userData || {}),
169
+ requester: this.LavalinkManager.utils.getTransformedRequester(options?.track?.requester || {})
170
+ };
171
+ return this.node.updatePlayer({
172
+ guildId: this.guildId,
173
+ noReplace: false,
174
+ playerOptions: Object.fromEntries(Object.entries({
175
+ track,
176
+ position: options.position ?? undefined,
177
+ paused: options.paused ?? undefined,
178
+ endTime: options?.endTime ?? undefined,
179
+ filters: options?.filters ?? undefined,
180
+ volume: options.volume ?? this.lavalinkVolume ?? undefined,
181
+ voice: options.voice ?? undefined,
182
+ }).filter(v => typeof v[1] !== "undefined")),
183
+ });
169
184
  }
170
185
  if (!this.queue.current && this.queue.tracks.length)
171
186
  await (0, Utils_1.queueTrackEnd)(this);
@@ -222,7 +237,7 @@ class Player {
222
237
  const now = performance.now();
223
238
  await this.node.updatePlayer({
224
239
  guildId: this.guildId,
225
- noReplace: replaced ? replaced : (options?.noReplace ?? false),
240
+ noReplace: (options?.noReplace ?? false),
226
241
  playerOptions: finalOptions,
227
242
  });
228
243
  this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
@@ -251,15 +266,32 @@ class Player {
251
266
  this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
252
267
  return this;
253
268
  }
269
+ /**
270
+ * Search for a track
271
+ * @param query The query to search for
272
+ * @param requestUser The user that requested the track
273
+ * @param throwOnEmpty If an error should be thrown if no track is found
274
+ * @returns The search result
275
+ */
254
276
  async lavaSearch(query, requestUser, throwOnEmpty = false) {
255
277
  return this.node.lavaSearch(query, requestUser, throwOnEmpty);
256
278
  }
279
+ /**
280
+ * Set the SponsorBlock
281
+ * @param segments The segments to set
282
+ */
257
283
  async setSponsorBlock(segments = ["sponsor", "selfpromo"]) {
258
284
  return this.node.setSponsorBlock(this, segments);
259
285
  }
286
+ /**
287
+ * Get the SponsorBlock
288
+ */
260
289
  async getSponsorBlock() {
261
290
  return this.node.getSponsorBlock(this);
262
291
  }
292
+ /**
293
+ * Delete the SponsorBlock
294
+ */
263
295
  async deleteSponsorBlock() {
264
296
  return this.node.deleteSponsorBlock(this);
265
297
  }
@@ -330,6 +362,7 @@ class Player {
330
362
  this.repeatMode = repeatMode;
331
363
  return this;
332
364
  }
365
+ 1;
333
366
  /**
334
367
  * Skip the current song, or a specific amount of songs
335
368
  * @param amount provide the index of the next track to skip to
@@ -343,7 +376,7 @@ class Player {
343
376
  await this.queue.splice(0, skipTo - 1);
344
377
  }
345
378
  if (!this.playing)
346
- return await this.play();
379
+ return (this.play(), this);
347
380
  const now = performance.now();
348
381
  this.set("internal_skipped", true);
349
382
  await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { track: { encoded: null } } });
@@ -505,6 +538,7 @@ class Player {
505
538
  filters: this.filterManager?.data || {},
506
539
  equalizer: this.filterManager?.equalizerBands || [],
507
540
  nodeId: this.node?.id,
541
+ nodeSessionId: this.node?.sessionId,
508
542
  ping: this.ping,
509
543
  queue: this.queue.utils.toJSON(),
510
544
  };