lavalink-client 2.5.7 → 2.5.9

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