lavalink-client 2.5.6 → 2.5.8

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 +9 -2
  2. package/dist/index.d.mts +3036 -0
  3. package/dist/index.d.ts +3036 -0
  4. package/dist/index.js +4965 -0
  5. package/dist/index.mjs +4904 -0
  6. package/package.json +22 -25
  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 -34
  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 -440
  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 -34
  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 -440
  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 -34
  96. package/dist/types/structures/Types/Track.d.ts +0 -134
  97. package/dist/types/structures/Types/Utils.d.ts +0 -440
  98. package/dist/types/structures/Utils.d.ts +0 -116
@@ -1,621 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LavalinkManager = void 0;
4
- const events_1 = require("events");
5
- const Constants_1 = require("./Constants.js");
6
- const NodeManager_1 = require("./NodeManager.js");
7
- const Player_1 = require("./Player.js");
8
- const Queue_1 = require("./Queue.js");
9
- const Utils_1 = require("./Utils.js");
10
- class LavalinkManager extends events_1.EventEmitter {
11
- /**
12
- * Emit an event
13
- * @param event The event to emit
14
- * @param args The arguments to pass to the event
15
- * @returns
16
- */
17
- emit(event, ...args) {
18
- return super.emit(event, ...args);
19
- }
20
- /**
21
- * Add an event listener
22
- * @param event The event to listen to
23
- * @param listener The listener to add
24
- * @returns
25
- */
26
- on(event, listener) {
27
- return super.on(event, listener);
28
- }
29
- /**
30
- * Add an event listener that only fires once
31
- * @param event The event to listen to
32
- * @param listener The listener to add
33
- * @returns
34
- */
35
- once(event, listener) {
36
- return super.once(event, listener);
37
- }
38
- /**
39
- * Remove an event listener
40
- * @param event The event to remove the listener from
41
- * @param listener The listener to remove
42
- * @returns
43
- */
44
- off(event, listener) {
45
- return super.off(event, listener);
46
- }
47
- /**
48
- * Remove an event listener
49
- * @param event The event to remove the listener from
50
- * @param listener The listener to remove
51
- * @returns
52
- */
53
- removeListener(event, listener) {
54
- return super.removeListener(event, listener);
55
- }
56
- /** The Options of LavalinkManager (changeable) */
57
- options;
58
- /** LavalinkManager's NodeManager to manage all Nodes */
59
- nodeManager;
60
- /** LavalinkManager's Utils Class */
61
- utils;
62
- /** Wether the manager was initiated or not */
63
- initiated = false;
64
- /** All Players stored in a MiniMap */
65
- players = new Utils_1.MiniMap();
66
- /**
67
- * Applies the options provided by the User
68
- * @param options
69
- * @returns
70
- */
71
- applyOptions(options) {
72
- this.options = {
73
- client: {
74
- ...options?.client,
75
- id: options?.client?.id,
76
- username: options?.client?.username ?? "lavalink-client"
77
- },
78
- sendToShard: options?.sendToShard,
79
- nodes: options?.nodes,
80
- playerOptions: {
81
- applyVolumeAsFilter: options?.playerOptions?.applyVolumeAsFilter ?? false,
82
- clientBasedPositionUpdateInterval: options?.playerOptions?.clientBasedPositionUpdateInterval ?? 100,
83
- defaultSearchPlatform: options?.playerOptions?.defaultSearchPlatform ?? "ytsearch",
84
- onDisconnect: {
85
- destroyPlayer: options?.playerOptions?.onDisconnect?.destroyPlayer ?? true,
86
- autoReconnect: options?.playerOptions?.onDisconnect?.autoReconnect ?? false,
87
- autoReconnectOnlyWithTracks: options?.playerOptions?.onDisconnect?.autoReconnectOnlyWithTracks ?? false,
88
- },
89
- onEmptyQueue: {
90
- autoPlayFunction: options?.playerOptions?.onEmptyQueue?.autoPlayFunction ?? null,
91
- destroyAfterMs: options?.playerOptions?.onEmptyQueue?.destroyAfterMs ?? undefined
92
- },
93
- volumeDecrementer: options?.playerOptions?.volumeDecrementer ?? 1,
94
- requesterTransformer: options?.playerOptions?.requesterTransformer ?? null,
95
- useUnresolvedData: options?.playerOptions?.useUnresolvedData ?? false,
96
- minAutoPlayMs: options?.playerOptions?.minAutoPlayMs ?? 10_000,
97
- maxErrorsPerTime: {
98
- threshold: options?.playerOptions?.maxErrorsPerTime?.threshold ?? 35_000,
99
- maxAmount: options?.playerOptions?.maxErrorsPerTime?.maxAmount ?? 3
100
- }
101
- },
102
- linksWhitelist: options?.linksWhitelist ?? [],
103
- linksBlacklist: options?.linksBlacklist ?? [],
104
- linksAllowed: options?.linksAllowed ?? true,
105
- autoSkip: options?.autoSkip ?? true,
106
- autoSkipOnResolveError: options?.autoSkipOnResolveError ?? true,
107
- emitNewSongsOnly: options?.emitNewSongsOnly ?? false,
108
- queueOptions: {
109
- maxPreviousTracks: options?.queueOptions?.maxPreviousTracks ?? 25,
110
- queueChangesWatcher: options?.queueOptions?.queueChangesWatcher ?? null,
111
- queueStore: options?.queueOptions?.queueStore ?? new Queue_1.DefaultQueueStore(),
112
- },
113
- advancedOptions: {
114
- enableDebugEvents: options?.advancedOptions?.enableDebugEvents ?? false,
115
- maxFilterFixDuration: options?.advancedOptions?.maxFilterFixDuration ?? 600_000,
116
- debugOptions: {
117
- logCustomSearches: options?.advancedOptions?.debugOptions?.logCustomSearches ?? false,
118
- noAudio: options?.advancedOptions?.debugOptions?.noAudio ?? false,
119
- playerDestroy: {
120
- dontThrowError: options?.advancedOptions?.debugOptions?.playerDestroy?.dontThrowError ?? false,
121
- debugLog: options?.advancedOptions?.debugOptions?.playerDestroy?.debugLog ?? false,
122
- }
123
- }
124
- }
125
- };
126
- return;
127
- }
128
- /**
129
- * Validates the current manager's options
130
- * @param options
131
- */
132
- validateOptions(options) {
133
- if (typeof options?.sendToShard !== "function")
134
- throw new SyntaxError("ManagerOption.sendToShard was not provided, which is required!");
135
- // only check in .init()
136
- // if(typeof options?.client !== "object" || typeof options?.client.id !== "string") throw new SyntaxError("ManagerOption.client = { id: string, username?:string } was not provided, which is required");
137
- if (options?.autoSkip && typeof options?.autoSkip !== "boolean")
138
- throw new SyntaxError("ManagerOption.autoSkip must be either false | true aka boolean");
139
- if (options?.autoSkipOnResolveError && typeof options?.autoSkipOnResolveError !== "boolean")
140
- throw new SyntaxError("ManagerOption.autoSkipOnResolveError must be either false | true aka boolean");
141
- if (options?.emitNewSongsOnly && typeof options?.emitNewSongsOnly !== "boolean")
142
- throw new SyntaxError("ManagerOption.emitNewSongsOnly must be either false | true aka boolean");
143
- if (!options?.nodes || !Array.isArray(options?.nodes) || !options?.nodes.every(node => this.utils.isNodeOptions(node)))
144
- throw new SyntaxError("ManagerOption.nodes must be an Array of NodeOptions and is required of at least 1 Node");
145
- /* QUEUE STORE */
146
- if (options?.queueOptions?.queueStore) {
147
- const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(options?.queueOptions?.queueStore));
148
- const requiredKeys = ["get", "set", "stringify", "parse", "delete"];
149
- if (!requiredKeys.every(v => keys.includes(v)) || !requiredKeys.every(v => typeof options?.queueOptions?.queueStore[v] === "function"))
150
- throw new SyntaxError(`The provided ManagerOption.QueueStore, does not have all required functions: ${requiredKeys.join(", ")}`);
151
- }
152
- /* QUEUE WATCHER */
153
- if (options?.queueOptions?.queueChangesWatcher) {
154
- const keys = Object.getOwnPropertyNames(Object.getPrototypeOf(options?.queueOptions?.queueChangesWatcher));
155
- const requiredKeys = ["tracksAdd", "tracksRemoved", "shuffled"];
156
- if (!requiredKeys.every(v => keys.includes(v)) || !requiredKeys.every(v => typeof options?.queueOptions?.queueChangesWatcher[v] === "function"))
157
- throw new SyntaxError(`The provided ManagerOption.DefaultQueueChangesWatcher, does not have all required functions: ${requiredKeys.join(", ")}`);
158
- }
159
- if (typeof options?.queueOptions?.maxPreviousTracks !== "number" || options?.queueOptions?.maxPreviousTracks < 0)
160
- options.queueOptions.maxPreviousTracks = 25;
161
- }
162
- /**
163
- * Create the Lavalink Manager
164
- * @param options
165
- *
166
- * @example
167
- * ```ts
168
- * //const client = new Client({...}); // create your BOT Client (e.g. via discord.js)
169
- * client.lavalink = new LavalinkManager({
170
- * nodes: [
171
- * {
172
- * authorization: "yourverystrongpassword",
173
- * host: "localhost",
174
- * port: 2333,
175
- * id: "testnode"
176
- * },
177
- * sendToShard(guildId, payload) => client.guilds.cache.get(guildId)?.shard?.send(payload),
178
- * client: {
179
- * id: process.env.CLIENT_ID,
180
- * username: "TESTBOT"
181
- * },
182
- * // optional Options:
183
- * autoSkip: true,
184
- * playerOptions: {
185
- * applyVolumeAsFilter: false,
186
- * clientBasedPositionUpdateInterval: 150,
187
- * defaultSearchPlatform: "ytmsearch",
188
- * volumeDecrementer: 0.75,
189
- * //requesterTransformer: YourRequesterTransformerFunction,
190
- * onDisconnect: {
191
- * autoReconnect: true,
192
- * destroyPlayer: false
193
- * },
194
- * onEmptyQueue: {
195
- * destroyAfterMs: 30_000,
196
- * //autoPlayFunction: YourAutoplayFunction,
197
- * },
198
- * useUnresolvedData: true
199
- * },
200
- * queueOptions: {
201
- * maxPreviousTracks: 25,
202
- * //queueStore: yourCustomQueueStoreManagerClass,
203
- * //queueChangesWatcher: yourCustomQueueChangesWatcherClass
204
- * },
205
- * linksBlacklist: [],
206
- * linksWhitelist: [],
207
- * advancedOptions: {
208
- * maxFilterFixDuration: 600_000,
209
- * debugOptions: {
210
- * noAudio: false,
211
- * playerDestroy: {
212
- * dontThrowError: false,
213
- * debugLogs: false
214
- * }
215
- * }
216
- * }
217
- * ]
218
- * })
219
- * ```
220
- */
221
- constructor(options) {
222
- super();
223
- if (!options)
224
- throw new SyntaxError("No Manager Options Provided");
225
- this.utils = new Utils_1.ManagerUtils(this);
226
- // use the validators
227
- this.applyOptions(options);
228
- this.validateOptions(this.options);
229
- // create classes
230
- this.nodeManager = new NodeManager_1.NodeManager(this);
231
- }
232
- /**
233
- * Get a Player from Lava
234
- * @param guildId The guildId of the player
235
- *
236
- * @example
237
- * ```ts
238
- * const player = client.lavalink.getPlayer(interaction.guildId);
239
- * ```
240
- * A quicker and easier way than doing:
241
- * ```ts
242
- * const player = client.lavalink.players.get(interaction.guildId);
243
- * ```
244
- * @returns
245
- */
246
- getPlayer(guildId) {
247
- return this.players.get(guildId);
248
- }
249
- /**
250
- * Create a Music-Player. If a player exists, then it returns it before creating a new one
251
- * @param options
252
- * @returns
253
- *
254
- * @example
255
- * ```ts
256
- * const player = client.lavalink.createPlayer({
257
- * guildId: interaction.guildId,
258
- * voiceChannelId: interaction.member.voice.channelId,
259
- * // everything below is optional
260
- * textChannelId: interaction.channelId,
261
- * volume: 100,
262
- * selfDeaf: true,
263
- * selfMute: false,
264
- * instaUpdateFiltersFix: true,
265
- * applyVolumeAsFilter: false
266
- * //only needed if you want to autopick node by region (configured by you)
267
- * // vcRegion: interaction.member.voice.rtcRegion,
268
- * // provide a specific node
269
- * // node: client.lavalink.nodeManager.leastUsedNodes("memory")[0]
270
- * });
271
- * ```
272
- */
273
- createPlayer(options) {
274
- const oldPlayer = this.getPlayer(options?.guildId);
275
- if (oldPlayer)
276
- return oldPlayer;
277
- const newPlayer = new Player_1.Player(options, this, true);
278
- this.players.set(newPlayer.guildId, newPlayer);
279
- this.emit("playerCreate", newPlayer);
280
- return newPlayer;
281
- }
282
- /**
283
- * Destroy a player with optional destroy reason and disconnect it from the voice channel
284
- * @param guildId
285
- * @param destroyReason
286
- * @returns
287
- *
288
- * @example
289
- * ```ts
290
- * client.lavalink.destroyPlayer(interaction.guildId, "forcefully destroyed the player");
291
- * // recommend to do it on the player tho: player.destroy("forcefully destroyed the player");
292
- * ```
293
- */
294
- destroyPlayer(guildId, destroyReason) {
295
- const oldPlayer = this.getPlayer(guildId);
296
- if (!oldPlayer)
297
- return;
298
- return oldPlayer.destroy(destroyReason);
299
- }
300
- /**
301
- * Delete's a player from the cache without destroying it on lavalink (only works when it's disconnected)
302
- * @param guildId
303
- * @returns
304
- *
305
- * @example
306
- * ```ts
307
- * client.lavalink.deletePlayer(interaction.guildId);
308
- * // shouldn't be used except you know what you are doing.
309
- * ```
310
- */
311
- deletePlayer(guildId) {
312
- const oldPlayer = this.getPlayer(guildId);
313
- if (!oldPlayer)
314
- return;
315
- // oldPlayer.connected is operational. you could also do oldPlayer.voice?.token
316
- if (oldPlayer.voiceChannelId === "string" && oldPlayer.connected && !oldPlayer.get("internal_destroywithoutdisconnect")) {
317
- if (!this.options?.advancedOptions?.debugOptions?.playerDestroy?.dontThrowError)
318
- throw new Error(`Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player ${(0, Utils_1.safeStringify)(oldPlayer.toJSON?.())}`);
319
- else if (this.options?.advancedOptions?.enableDebugEvents) {
320
- this.emit("debug", Constants_1.DebugEvents.PlayerDeleteInsteadOfDestroy, {
321
- state: "warn",
322
- message: "Use Player#destroy() not LavalinkManager#deletePlayer() to stop the Player",
323
- functionLayer: "LavalinkManager > deletePlayer()",
324
- });
325
- }
326
- }
327
- return this.players.delete(guildId);
328
- }
329
- /**
330
- * Checks wether the the lib is useable based on if any node is connected
331
- *
332
- * @example
333
- * ```ts
334
- * if(!client.lavalink.useable) return console.error("can'T search yet, because there is no useable lavalink node.")
335
- * // continue with code e.g. createing a player and searching
336
- * ```
337
- */
338
- get useable() {
339
- return this.nodeManager.nodes.filter(v => v.connected).size > 0;
340
- }
341
- /**
342
- * Initiates the Manager, creates all nodes and connects all of them
343
- * @param clientData
344
- *
345
- * @example
346
- * ```ts
347
- * // on the bot ready event
348
- * client.on("ready", () => {
349
- * client.lavalink.init({
350
- * id: client.user.id,
351
- * username: client.user.username
352
- * });
353
- * });
354
- * ```
355
- */
356
- async init(clientData) {
357
- if (this.initiated)
358
- return this;
359
- clientData = clientData ?? {};
360
- this.options.client = { ...this.options?.client, ...clientData };
361
- if (!this.options?.client.id)
362
- throw new Error('"client.id" is not set. Pass it in Manager#init() or as a option in the constructor.');
363
- if (typeof this.options?.client.id !== "string")
364
- throw new Error('"client.id" set is not type of "string"');
365
- let success = 0;
366
- for (const node of this.nodeManager.nodes.values()) {
367
- try {
368
- await node.connect();
369
- success++;
370
- }
371
- catch (err) {
372
- console.error(err);
373
- this.nodeManager.emit("error", node, err);
374
- }
375
- }
376
- if (success > 0)
377
- this.initiated = true;
378
- else if (this.options?.advancedOptions?.enableDebugEvents) {
379
- this.emit("debug", Constants_1.DebugEvents.FailedToConnectToNodes, {
380
- state: "error",
381
- message: "Failed to connect to at least 1 Node",
382
- functionLayer: "LavalinkManager > init()",
383
- });
384
- }
385
- return this;
386
- }
387
- /**
388
- * Sends voice data to the Lavalink server.
389
- * ! Without this the library won't work
390
- * @param data
391
- *
392
- * @example
393
- *
394
- * ```ts
395
- * // on the bot "raw" event
396
- * client.on("raw", (d) => {
397
- * // required in order to send audio updates and register channel deletion etc.
398
- * client.lavalink.sendRawData(d)
399
- * })
400
- * ```
401
- */
402
- async sendRawData(data) {
403
- if (!this.initiated) {
404
- if (this.options?.advancedOptions?.enableDebugEvents) {
405
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
406
- state: "log",
407
- message: "Manager is not initated yet",
408
- functionLayer: "LavalinkManager > sendRawData()",
409
- });
410
- }
411
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
412
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, manager is not initated yet");
413
- return;
414
- }
415
- if (!("t" in data)) {
416
- if (this.options?.advancedOptions?.enableDebugEvents) {
417
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
418
- state: "error",
419
- message: "No 't' in payload-data of the raw event:",
420
- functionLayer: "LavalinkManager > sendRawData()",
421
- });
422
- }
423
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
424
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 't' in payload-data of the raw event:", data);
425
- return;
426
- }
427
- // for channel Delete
428
- if ("CHANNEL_DELETE" === data.t) {
429
- const update = "d" in data ? data.d : data;
430
- if (!update.guild_id)
431
- return;
432
- const player = this.getPlayer(update.guild_id);
433
- if (player && player.voiceChannelId === update.id)
434
- return void player.destroy(Constants_1.DestroyReasons.ChannelDeleted);
435
- }
436
- // for voice updates
437
- if (["VOICE_STATE_UPDATE", "VOICE_SERVER_UPDATE"].includes(data.t)) {
438
- const update = ("d" in data ? data.d : data);
439
- if (!update) {
440
- if (this.options?.advancedOptions?.enableDebugEvents) {
441
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
442
- state: "warn",
443
- message: `No Update data found in payload :: ${(0, Utils_1.safeStringify)(data, 2)}`,
444
- functionLayer: "LavalinkManager > sendRawData()",
445
- });
446
- }
447
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
448
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no update data found in payload:", data);
449
- return;
450
- }
451
- if (!("token" in update) && !("session_id" in update)) {
452
- if (this.options?.advancedOptions?.enableDebugEvents) {
453
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
454
- state: "error",
455
- message: `No 'token' nor 'session_id' found in payload :: ${(0, Utils_1.safeStringify)(data, 2)}`,
456
- functionLayer: "LavalinkManager > sendRawData()",
457
- });
458
- }
459
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
460
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, no 'token' nor 'session_id' found in payload:", data);
461
- return;
462
- }
463
- const player = this.getPlayer(update.guild_id);
464
- if (!player) {
465
- if (this.options?.advancedOptions?.enableDebugEvents) {
466
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
467
- state: "warn",
468
- message: `No Lavalink Player found via key: 'guild_id' of update-data :: ${(0, Utils_1.safeStringify)(update, 2)}`,
469
- functionLayer: "LavalinkManager > sendRawData()",
470
- });
471
- }
472
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
473
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, No Lavalink Player found via key: 'guild_id' of update-data:", update);
474
- return;
475
- }
476
- if (player.get("internal_destroystatus") === true) {
477
- if (this.options?.advancedOptions?.enableDebugEvents) {
478
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
479
- state: "warn",
480
- message: `Player is in a destroying state. can't signal the voice states`,
481
- functionLayer: "LavalinkManager > sendRawData()",
482
- });
483
- }
484
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
485
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Player is in a destroying state. can't signal the voice states");
486
- return;
487
- }
488
- if ("token" in update) {
489
- if (!player.node?.sessionId)
490
- throw new Error("Lavalink Node is either not ready or not up to date");
491
- const sessionId2Use = player.voice?.sessionId || ("sessionId" in update ? update.sessionId : undefined);
492
- if (!sessionId2Use) {
493
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
494
- state: "error",
495
- message: `Can't send updatePlayer for voice token session - Missing sessionId :: ${(0, Utils_1.safeStringify)({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, 2)}`,
496
- functionLayer: "LavalinkManager > sendRawData()",
497
- });
498
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
499
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Can't send updatePlayer for voice token session - Missing sessionId", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice });
500
- }
501
- else {
502
- await player.node.updatePlayer({
503
- guildId: player.guildId,
504
- playerOptions: {
505
- voice: {
506
- token: update.token,
507
- endpoint: update.endpoint,
508
- sessionId: sessionId2Use,
509
- },
510
- },
511
- });
512
- if (this.options?.advancedOptions?.enableDebugEvents) {
513
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
514
- state: "log",
515
- message: `Sent updatePlayer for voice token session :: ${(0, Utils_1.safeStringify)({ voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, update, playerVoice: player.voice }, 2)}`,
516
- functionLayer: "LavalinkManager > sendRawData()",
517
- });
518
- }
519
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
520
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Sent updatePlayer for voice token session", { voice: { token: update.token, endpoint: update.endpoint, sessionId: sessionId2Use, }, playerVoice: player.voice, update });
521
- }
522
- return;
523
- }
524
- /* voice state update */
525
- if (update.user_id !== this.options?.client.id) {
526
- if (update.user_id && player.voiceChannelId) {
527
- this.emit(update.channel_id === player.voiceChannelId ? "playerVoiceJoin" : "playerVoiceLeave", player, update.user_id);
528
- }
529
- if (this.options?.advancedOptions?.enableDebugEvents) {
530
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
531
- state: "warn",
532
- message: `voice update user is not equal to provided client id of the LavalinkManager.options.client.id :: user: "${update.user_id}" manager client id: "${this.options?.client.id}"`,
533
- functionLayer: "LavalinkManager > sendRawData()",
534
- });
535
- }
536
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
537
- console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, voice update user is not equal to provided client id of the manageroptions#client#id", "user:", update.user_id, "manager client id:", this.options?.client.id);
538
- return;
539
- }
540
- if (update.channel_id) {
541
- if (player.voiceChannelId !== update.channel_id)
542
- this.emit("playerMove", player, player.voiceChannelId, update.channel_id);
543
- player.voice.sessionId = update.session_id || player.voice.sessionId;
544
- if (!player.voice.sessionId) {
545
- if (this.options?.advancedOptions?.enableDebugEvents) {
546
- this.emit("debug", Constants_1.DebugEvents.NoAudioDebug, {
547
- state: "warn",
548
- message: `Function to assing sessionId provided, but no found in Payload: ${(0, Utils_1.safeStringify)({ update, playerVoice: player.voice }, 2)}`,
549
- functionLayer: "LavalinkManager > sendRawData()",
550
- });
551
- }
552
- if (this.options?.advancedOptions?.debugOptions?.noAudio === true)
553
- console.debug(`Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Function to assing sessionId provided, but no found in Payload: ${(0, Utils_1.safeStringify)(update, 2)}`);
554
- }
555
- player.voiceChannelId = update.channel_id;
556
- const selfMuteChanged = typeof update.self_mute === "boolean" && player.voiceState.selfMute !== update.self_mute;
557
- const serverMuteChanged = typeof update.mute === "boolean" && player.voiceState.serverMute !== update.mute;
558
- const selfDeafChanged = typeof update.self_deaf === "boolean" && player.voiceState.selfDeaf !== update.self_deaf;
559
- const serverDeafChanged = typeof update.deaf === "boolean" && player.voiceState.serverDeaf !== update.deaf;
560
- const suppressChange = typeof update.suppress === "boolean" && player.voiceState.suppress !== update.suppress;
561
- player.voiceState.selfDeaf = update.self_deaf ?? player.voiceState?.selfDeaf;
562
- player.voiceState.selfMute = update.self_mute ?? player.voiceState?.selfMute;
563
- player.voiceState.serverDeaf = update.deaf ?? player.voiceState?.serverDeaf;
564
- player.voiceState.serverMute = update.mute ?? player.voiceState?.serverMute;
565
- player.voiceState.suppress = update.suppress ?? player.voiceState?.suppress;
566
- if (selfMuteChanged || serverMuteChanged)
567
- this.emit("playerMuteChange", player, player.voiceState.selfMute, player.voiceState.serverMute);
568
- if (selfDeafChanged || serverDeafChanged)
569
- this.emit("playerDeafChange", player, player.voiceState.selfDeaf, player.voiceState.serverDeaf);
570
- if (suppressChange)
571
- this.emit("playerSuppressChange", player, player.voiceState.suppress);
572
- }
573
- else {
574
- const { autoReconnectOnlyWithTracks, destroyPlayer, autoReconnect } = this.options?.playerOptions?.onDisconnect ?? {};
575
- if (destroyPlayer === true) {
576
- return void await player.destroy(Constants_1.DestroyReasons.Disconnected);
577
- }
578
- if (autoReconnect === true) {
579
- try {
580
- const previousPosition = player.position;
581
- const previousPaused = player.paused;
582
- if (this.options?.advancedOptions?.enableDebugEvents) {
583
- this.emit("debug", Constants_1.DebugEvents.PlayerAutoReconnect, {
584
- state: "log",
585
- message: `Auto reconnecting player because LavalinkManager.options.playerOptions.onDisconnect.autoReconnect is true`,
586
- functionLayer: "LavalinkManager > sendRawData()",
587
- });
588
- }
589
- // connect if there are tracks & autoReconnectOnlyWithTracks = true or autoReconnectOnlyWithTracks is false
590
- if (!autoReconnectOnlyWithTracks || (autoReconnectOnlyWithTracks && (player.queue.current || player.queue.tracks.length))) {
591
- await player.connect();
592
- }
593
- // replay the current playing stream
594
- if (player.queue.current) {
595
- return void await player.play({ position: previousPosition, paused: previousPaused, clientTrack: player.queue.current, });
596
- }
597
- // try to play the next track
598
- if (player.queue.tracks.length) {
599
- return void await player.play({ paused: previousPaused });
600
- }
601
- // debug log if nothing was possible
602
- this.emit("debug", Constants_1.DebugEvents.PlayerAutoReconnect, {
603
- state: "log",
604
- message: `Auto reconnected, but nothing to play`,
605
- functionLayer: "LavalinkManager > sendRawData()",
606
- });
607
- }
608
- catch (e) {
609
- console.error(e);
610
- return void await player.destroy(Constants_1.DestroyReasons.PlayerReconnectFail);
611
- }
612
- }
613
- this.emit("playerDisconnect", player, player.voiceChannelId);
614
- player.voiceChannelId = null;
615
- player.voice = Object.assign({});
616
- return;
617
- }
618
- }
619
- }
620
- }
621
- exports.LavalinkManager = LavalinkManager;
@@ -1,15 +0,0 @@
1
- import type { ClientCustomSearchPlatformUtils, LavalinkSearchPlatform, SearchPlatform, SourcesRegex } from "./Types/Utils.js";
2
- /** Default Sources Record, to allow source parsing with multiple inputs. */
3
- export declare const DefaultSources: Record<SearchPlatform, LavalinkSearchPlatform | ClientCustomSearchPlatformUtils>;
4
- /** Lavalink Plugins definiton */
5
- export declare const LavalinkPlugins: {
6
- DuncteBot_Plugin: string;
7
- LavaSrc: string;
8
- GoogleCloudTTS: string;
9
- LavaSearch: string;
10
- Jiosaavn_Plugin: string;
11
- LavalinkFilterPlugin: string;
12
- JavaTimedLyricsPlugin: string;
13
- };
14
- /** Lavalink Sources regexes for url validations */
15
- export declare const SourceLinksRegexes: Record<SourcesRegex, RegExp>;