lavalink-client 2.5.7 → 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 +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,696 +0,0 @@
1
- import { audioOutputsData } from "./Constants.js";
2
- import { safeStringify } from "./Utils.js";
3
- /**
4
- * The FilterManager for each player
5
- */
6
- export class FilterManager {
7
- /** The Equalizer bands currently applied to the Lavalink Server */
8
- equalizerBands = [];
9
- /** Private Util for the instaFix Filters option */
10
- filterUpdatedState = false;
11
- /** All "Active" / "disabled" Player Filters */
12
- filters = {
13
- volume: false,
14
- vaporwave: false,
15
- custom: false,
16
- nightcore: false,
17
- rotation: false,
18
- karaoke: false,
19
- tremolo: false,
20
- vibrato: false,
21
- lowPass: false,
22
- lavalinkFilterPlugin: {
23
- echo: false,
24
- reverb: false,
25
- },
26
- lavalinkLavaDspxPlugin: {
27
- lowPass: false,
28
- highPass: false,
29
- normalization: false,
30
- echo: false,
31
- },
32
- audioOutput: "stereo",
33
- };
34
- /** The Filter Data sent to Lavalink, only if the filter is enabled (ofc.) */
35
- data = {
36
- lowPass: {
37
- smoothing: 0
38
- },
39
- karaoke: {
40
- level: 0,
41
- monoLevel: 0,
42
- filterBand: 0,
43
- filterWidth: 0
44
- },
45
- timescale: {
46
- speed: 1, // 0 = x
47
- pitch: 1, // 0 = x
48
- rate: 1 // 0 = x
49
- },
50
- rotation: {
51
- rotationHz: 0
52
- },
53
- tremolo: {
54
- frequency: 0, // 0 < x
55
- depth: 0 // 0 < x = 1
56
- },
57
- vibrato: {
58
- frequency: 0, // 0 < x <= 14
59
- depth: 0 // 0 < x <= 1
60
- },
61
- pluginFilters: {
62
- "lavalink-filter-plugin": {
63
- echo: {
64
- delay: 0, // in seconds
65
- decay: 0 // 0 < 1
66
- },
67
- reverb: {
68
- delays: [], // [0.037, 0.042, 0.048, 0.053]
69
- gains: [] // [0.84, 0.83, 0.82, 0.81]
70
- }
71
- },
72
- "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
73
- // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
74
- // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
75
- },
76
- "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
77
- // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
78
- // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
79
- },
80
- "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
81
- // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
82
- // "adaptive": true // false
83
- },
84
- "echo": { // Self-explanatory; provides an echo effect.
85
- // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
86
- // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
87
- },
88
- },
89
- channelMix: audioOutputsData.stereo,
90
- /*distortion: {
91
- sinOffset: 0,
92
- sinScale: 1,
93
- cosOffset: 0,
94
- cosScale: 1,
95
- tanOffset: 0,
96
- tanScale: 1,
97
- offset: 0,
98
- scale: 1
99
- }*/
100
- };
101
- /** The Player assigned to this Filter Manager */
102
- player;
103
- /** The Constructor for the FilterManager */
104
- constructor(player) {
105
- /** Assign the player to the filter manager */
106
- this.player = player;
107
- }
108
- /**
109
- * Apply Player filters for lavalink filter sending data, if the filter is enabled / not
110
- */
111
- async applyPlayerFilters() {
112
- const sendData = { ...this.data };
113
- this.checkFiltersState();
114
- if (!this.filters.volume)
115
- delete sendData.volume;
116
- if (!this.filters.tremolo)
117
- delete sendData.tremolo;
118
- if (!this.filters.vibrato)
119
- delete sendData.vibrato;
120
- if (!this.filters.lavalinkFilterPlugin.echo)
121
- delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.echo;
122
- if (!this.filters.lavalinkFilterPlugin.reverb)
123
- delete sendData.pluginFilters?.["lavalink-filter-plugin"]?.reverb;
124
- if (!this.filters.lavalinkLavaDspxPlugin.echo)
125
- delete sendData.pluginFilters?.echo;
126
- if (!this.filters.lavalinkLavaDspxPlugin.normalization)
127
- delete sendData.pluginFilters?.normalization;
128
- if (!this.filters.lavalinkLavaDspxPlugin.highPass)
129
- delete sendData.pluginFilters?.["high-pass"];
130
- if (!this.filters.lavalinkLavaDspxPlugin.lowPass)
131
- delete sendData.pluginFilters?.["low-pass"];
132
- if (sendData.pluginFilters?.["lavalink-filter-plugin"] && Object.values(sendData.pluginFilters?.["lavalink-filter-plugin"]).length === 0)
133
- delete sendData.pluginFilters["lavalink-filter-plugin"];
134
- if (sendData.pluginFilters && Object.values(sendData.pluginFilters).length === 0)
135
- delete sendData.pluginFilters;
136
- if (!this.filters.lowPass)
137
- delete sendData.lowPass;
138
- if (!this.filters.karaoke)
139
- delete sendData.karaoke;
140
- if (!this.filters.rotation)
141
- delete sendData.rotation;
142
- if (this.filters.audioOutput === "stereo")
143
- delete sendData.channelMix;
144
- if (Object.values(this.data.timescale).every(v => v === 1))
145
- delete sendData.timescale;
146
- if (!this.player.node.sessionId)
147
- throw new Error("The Lavalink-Node is either not ready or not up to date");
148
- sendData.equalizer = [...this.equalizerBands];
149
- if (sendData.equalizer.length === 0)
150
- delete sendData.equalizer;
151
- for (const key of Object.keys(sendData)) {
152
- // delete disabled filters
153
- if (key === "pluginFilters") {
154
- // for(const key of [...Object.keys(sendData.pluginFilters)]) {
155
- // // if (this.player.node.info && !this.player.node.info?.plugins?.find?.(v => v.name === key)) delete sendData[key];
156
- // }
157
- }
158
- else if (this.player.node.info && !this.player.node.info?.filters?.includes?.(key))
159
- delete sendData[key];
160
- }
161
- const now = performance.now();
162
- if (this.player.options.instaUpdateFiltersFix === true)
163
- this.filterUpdatedState = true;
164
- await this.player.node.updatePlayer({
165
- guildId: this.player.guildId,
166
- playerOptions: {
167
- filters: sendData,
168
- }
169
- });
170
- this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
171
- return;
172
- }
173
- /**
174
- * Checks if the filters are correctly stated (active / not-active)
175
- * @param oldFilterTimescale
176
- * @returns
177
- */
178
- checkFiltersState(oldFilterTimescale) {
179
- this.filters.rotation = this.data.rotation.rotationHz !== 0;
180
- this.filters.vibrato = this.data.vibrato.frequency !== 0 || this.data.vibrato.depth !== 0;
181
- this.filters.tremolo = this.data.tremolo.frequency !== 0 || this.data.tremolo.depth !== 0;
182
- const lavalinkFilterData = (this.data.pluginFilters?.["lavalink-filter-plugin"] || { echo: { decay: this.data.pluginFilters?.echo?.decay && !this.data.pluginFilters?.echo?.echoLength ? this.data.pluginFilters.echo.decay : 0, delay: this.data.pluginFilters?.echo?.delay || 0 }, reverb: { gains: [], delays: [], ...(this.data.pluginFilters.reverb) } });
183
- this.filters.lavalinkFilterPlugin.echo = lavalinkFilterData.echo.decay !== 0 || lavalinkFilterData.echo.delay !== 0;
184
- this.filters.lavalinkFilterPlugin.reverb = lavalinkFilterData.reverb?.delays?.length !== 0 || lavalinkFilterData.reverb?.gains?.length !== 0;
185
- this.filters.lavalinkLavaDspxPlugin.highPass = Object.values(this.data.pluginFilters["high-pass"] || {}).length > 0;
186
- this.filters.lavalinkLavaDspxPlugin.lowPass = Object.values(this.data.pluginFilters["low-pass"] || {}).length > 0;
187
- this.filters.lavalinkLavaDspxPlugin.normalization = Object.values(this.data.pluginFilters.normalization || {}).length > 0;
188
- this.filters.lavalinkLavaDspxPlugin.echo = Object.values(this.data.pluginFilters.echo || {}).length > 0 && typeof this.data.pluginFilters?.echo?.delay === "undefined";
189
- this.filters.lowPass = this.data.lowPass.smoothing !== 0;
190
- this.filters.karaoke = Object.values(this.data.karaoke).some(v => v !== 0);
191
- if ((this.filters.nightcore || this.filters.vaporwave) && oldFilterTimescale) {
192
- if (oldFilterTimescale.pitch !== this.data.timescale.pitch || oldFilterTimescale.rate !== this.data.timescale.rate || oldFilterTimescale.speed !== this.data.timescale.speed) {
193
- this.filters.custom = Object.values(this.data.timescale).some(v => v !== 1);
194
- this.filters.nightcore = false;
195
- this.filters.vaporwave = false;
196
- }
197
- }
198
- return true;
199
- }
200
- /**
201
- * Reset all Filters
202
- */
203
- async resetFilters() {
204
- this.filters.lavalinkLavaDspxPlugin.echo = false;
205
- this.filters.lavalinkLavaDspxPlugin.normalization = false;
206
- this.filters.lavalinkLavaDspxPlugin.highPass = false;
207
- this.filters.lavalinkLavaDspxPlugin.lowPass = false;
208
- this.filters.lavalinkFilterPlugin.echo = false;
209
- this.filters.lavalinkFilterPlugin.reverb = false;
210
- this.filters.nightcore = false;
211
- this.filters.lowPass = false;
212
- this.filters.rotation = false;
213
- this.filters.tremolo = false;
214
- this.filters.vibrato = false;
215
- this.filters.karaoke = false;
216
- this.filters.karaoke = false;
217
- this.filters.volume = false;
218
- this.filters.audioOutput = "stereo";
219
- // reset all filter datas
220
- for (const [key, value] of Object.entries({
221
- volume: 1,
222
- lowPass: {
223
- smoothing: 0
224
- },
225
- karaoke: {
226
- level: 0,
227
- monoLevel: 0,
228
- filterBand: 0,
229
- filterWidth: 0
230
- },
231
- timescale: {
232
- speed: 1, // 0 = x
233
- pitch: 1, // 0 = x
234
- rate: 1 // 0 = x
235
- },
236
- pluginFilters: {
237
- "lavalink-filter-plugin": {
238
- echo: {
239
- // delay: 0, // in seconds
240
- // decay: 0 // 0 < 1
241
- },
242
- reverb: {
243
- // delays: [], // [0.037, 0.042, 0.048, 0.053]
244
- // gains: [] // [0.84, 0.83, 0.82, 0.81]
245
- }
246
- },
247
- "high-pass": { // Cuts off frequencies lower than the specified {cutoffFrequency}.
248
- // "cutoffFrequency": 1475, // Integer, higher than zero, in Hz.
249
- // "boostFactor": 1.0 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
250
- },
251
- "low-pass": { // Cuts off frequencies higher than the specified {cutoffFrequency}.
252
- // "cutoffFrequency": 284, // Integer, higher than zero, in Hz.
253
- // "boostFactor": 1.24389 // Float, higher than 0.0. This alters volume output. A value of 1.0 means no volume change.
254
- },
255
- "normalization": { // Attenuates peaking where peaks are defined as having a higher value than {maxAmplitude}.
256
- // "maxAmplitude": 0.6327, // Float, within the range of 0.0 - 1.0. A value of 0.0 mutes the output.
257
- // "adaptive": true // false
258
- },
259
- "echo": { // Self-explanatory; provides an echo effect.
260
- // "echoLength": 0.5649, // Float, higher than 0.0, in seconds (1.0 = 1 second).
261
- // "decay": 0.4649 // Float, within the range of 0.0 - 1.0. A value of 1.0 means no decay, and a value of 0.0 means
262
- },
263
- },
264
- rotation: {
265
- rotationHz: 0
266
- },
267
- tremolo: {
268
- frequency: 0, // 0 < x
269
- depth: 0 // 0 < x = 1
270
- },
271
- vibrato: {
272
- frequency: 0, // 0 < x = 14
273
- depth: 0 // 0 < x = 1
274
- },
275
- channelMix: audioOutputsData.stereo,
276
- })) {
277
- this.data[key] = value;
278
- }
279
- await this.applyPlayerFilters();
280
- return this.filters;
281
- }
282
- /**
283
- * Set the Filter Volume
284
- * @param volume
285
- * @returns
286
- */
287
- async setVolume(volume) {
288
- if (volume < 0 || volume > 5)
289
- throw new SyntaxError("Volume-Filter must be between 0 and 5");
290
- this.data.volume = volume;
291
- await this.applyPlayerFilters();
292
- return this.filters.volume;
293
- }
294
- /**
295
- * Set the AudioOutput Filter
296
- * @param type
297
- * @returns
298
- */
299
- async setAudioOutput(type) {
300
- if (this.player.node.info && !this.player.node.info?.filters?.includes("channelMix"))
301
- throw new Error("Node#Info#filters does not include the 'channelMix' Filter (Node has it not enable)");
302
- if (!type || !audioOutputsData[type])
303
- throw "Invalid audio type added, must be 'mono' / 'stereo' / 'left' / 'right'";
304
- this.data.channelMix = audioOutputsData[type];
305
- this.filters.audioOutput = type;
306
- await this.applyPlayerFilters();
307
- return this.filters.audioOutput;
308
- }
309
- /**
310
- * Set custom filter.timescale#speed . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
311
- * @param speed
312
- * @returns
313
- */
314
- async setSpeed(speed = 1) {
315
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
316
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
317
- // reset nightcore / vaporwave filter if enabled
318
- if (this.filters.nightcore || this.filters.vaporwave) {
319
- this.data.timescale.pitch = 1;
320
- this.data.timescale.speed = 1;
321
- this.data.timescale.rate = 1;
322
- this.filters.nightcore = false;
323
- this.filters.vaporwave = false;
324
- }
325
- this.data.timescale.speed = speed;
326
- // check if custom filter is active / not
327
- this.isCustomFilterActive();
328
- await this.applyPlayerFilters();
329
- return this.filters.custom;
330
- }
331
- /**
332
- * Set custom filter.timescale#pitch . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
333
- * @param speed
334
- * @returns
335
- */
336
- async setPitch(pitch = 1) {
337
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
338
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
339
- // reset nightcore / vaporwave filter if enabled
340
- if (this.filters.nightcore || this.filters.vaporwave) {
341
- this.data.timescale.pitch = 1;
342
- this.data.timescale.speed = 1;
343
- this.data.timescale.rate = 1;
344
- this.filters.nightcore = false;
345
- this.filters.vaporwave = false;
346
- }
347
- this.data.timescale.pitch = pitch;
348
- // check if custom filter is active / not
349
- this.isCustomFilterActive();
350
- await this.applyPlayerFilters();
351
- return this.filters.custom;
352
- }
353
- /**
354
- * Set custom filter.timescale#rate . This method disabled both: nightcore & vaporwave. use 1 to reset it to normal
355
- * @param speed
356
- * @returns
357
- */
358
- async setRate(rate = 1) {
359
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
360
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
361
- // reset nightcore / vaporwave filter if enabled
362
- if (this.filters.nightcore || this.filters.vaporwave) {
363
- this.data.timescale.pitch = 1;
364
- this.data.timescale.speed = 1;
365
- this.data.timescale.rate = 1;
366
- this.filters.nightcore = false;
367
- this.filters.vaporwave = false;
368
- }
369
- this.data.timescale.rate = rate;
370
- // check if custom filter is active / not
371
- this.isCustomFilterActive();
372
- await this.applyPlayerFilters();
373
- return this.filters.custom;
374
- }
375
- /**
376
- * Enables / Disables the rotation effect, (Optional: provide your Own Data)
377
- * @param rotationHz
378
- * @returns
379
- */
380
- async toggleRotation(rotationHz = 0.2) {
381
- if (this.player.node.info && !this.player.node.info?.filters?.includes("rotation"))
382
- throw new Error("Node#Info#filters does not include the 'rotation' Filter (Node has it not enable)");
383
- this.data.rotation.rotationHz = this.filters.rotation ? 0 : rotationHz;
384
- this.filters.rotation = !this.filters.rotation;
385
- await this.applyPlayerFilters();
386
- return this.filters.rotation;
387
- }
388
- /**
389
- * Enables / Disables the Vibrato effect, (Optional: provide your Own Data)
390
- * @param frequency
391
- * @param depth
392
- * @returns
393
- */
394
- async toggleVibrato(frequency = 10, depth = 1) {
395
- if (this.player.node.info && !this.player.node.info?.filters?.includes("vibrato"))
396
- throw new Error("Node#Info#filters does not include the 'vibrato' Filter (Node has it not enable)");
397
- this.data.vibrato.frequency = this.filters.vibrato ? 0 : frequency;
398
- this.data.vibrato.depth = this.filters.vibrato ? 0 : depth;
399
- this.filters.vibrato = !this.filters.vibrato;
400
- await this.applyPlayerFilters();
401
- return this.filters.vibrato;
402
- }
403
- /**
404
- * Enables / Disables the Tremolo effect, (Optional: provide your Own Data)
405
- * @param frequency
406
- * @param depth
407
- * @returns
408
- */
409
- async toggleTremolo(frequency = 4, depth = 0.8) {
410
- if (this.player.node.info && !this.player.node.info?.filters?.includes("tremolo"))
411
- throw new Error("Node#Info#filters does not include the 'tremolo' Filter (Node has it not enable)");
412
- this.data.tremolo.frequency = this.filters.tremolo ? 0 : frequency;
413
- this.data.tremolo.depth = this.filters.tremolo ? 0 : depth;
414
- this.filters.tremolo = !this.filters.tremolo;
415
- await this.applyPlayerFilters();
416
- return this.filters.tremolo;
417
- }
418
- /**
419
- * Enables / Disables the LowPass effect, (Optional: provide your Own Data)
420
- * @param smoothing
421
- * @returns
422
- */
423
- async toggleLowPass(smoothing = 20) {
424
- if (this.player.node.info && !this.player.node.info?.filters?.includes("lowPass"))
425
- throw new Error("Node#Info#filters does not include the 'lowPass' Filter (Node has it not enable)");
426
- this.data.lowPass.smoothing = this.filters.lowPass ? 0 : smoothing;
427
- this.filters.lowPass = !this.filters.lowPass;
428
- await this.applyPlayerFilters();
429
- return this.filters.lowPass;
430
- }
431
- lavalinkLavaDspxPlugin = {
432
- /**
433
- * Enables / Disables the LowPass effect, (Optional: provide your Own Data)
434
- * @param boostFactor
435
- * @param cutoffFrequency
436
- * @returns
437
- */
438
- toggleLowPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
439
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
440
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
441
- if (this.player.node.info && !this.player.node.info?.filters?.includes("low-pass"))
442
- throw new Error("Node#Info#filters does not include the 'low-pass' Filter (Node has it not enable)");
443
- if (!this.data)
444
- this.data = {};
445
- if (!this.data.pluginFilters)
446
- this.data.pluginFilters = {};
447
- if (!this.data.pluginFilters["low-pass"])
448
- this.data.pluginFilters["low-pass"] = {};
449
- if (this.filters.lavalinkLavaDspxPlugin.lowPass) {
450
- delete this.data.pluginFilters["low-pass"];
451
- }
452
- else {
453
- this.data.pluginFilters["low-pass"] = {
454
- boostFactor: boostFactor,
455
- cutoffFrequency: cutoffFrequency
456
- };
457
- }
458
- this.filters.lavalinkLavaDspxPlugin.lowPass = !this.filters.lavalinkLavaDspxPlugin.lowPass;
459
- await this.applyPlayerFilters();
460
- return this.filters.lavalinkLavaDspxPlugin.lowPass;
461
- },
462
- /**
463
- * Enables / Disables the HighPass effect, (Optional: provide your Own Data)
464
- * @param boostFactor
465
- * @param cutoffFrequency
466
- * @returns
467
- */
468
- toggleHighPass: async (boostFactor = 1.0, cutoffFrequency = 80) => {
469
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
470
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
471
- if (this.player.node.info && !this.player.node.info?.filters?.includes("high-pass"))
472
- throw new Error("Node#Info#filters does not include the 'high-pass' Filter (Node has it not enable)");
473
- if (!this.data)
474
- this.data = {};
475
- if (!this.data.pluginFilters)
476
- this.data.pluginFilters = {};
477
- if (!this.data.pluginFilters["high-pass"])
478
- this.data.pluginFilters["high-pass"] = {};
479
- if (this.filters.lavalinkLavaDspxPlugin.highPass) {
480
- delete this.data.pluginFilters["high-pass"];
481
- }
482
- else {
483
- this.data.pluginFilters["high-pass"] = {
484
- boostFactor: boostFactor,
485
- cutoffFrequency: cutoffFrequency
486
- };
487
- }
488
- this.filters.lavalinkLavaDspxPlugin.highPass = !this.filters.lavalinkLavaDspxPlugin.highPass;
489
- await this.applyPlayerFilters();
490
- return this.filters.lavalinkLavaDspxPlugin.highPass;
491
- },
492
- /**
493
- * Enables / Disables the Normalization effect.
494
- * @param {number} [maxAmplitude=0.75] - The maximum amplitude of the audio.
495
- * @param {boolean} [adaptive=true] - Whether to use adaptive normalization or not.
496
- * @returns {Promise<boolean>} - The state of the filter after execution.
497
- */
498
- toggleNormalization: async (maxAmplitude = 0.75, adaptive = true) => {
499
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
500
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
501
- if (this.player.node.info && !this.player.node.info?.filters?.includes("normalization"))
502
- throw new Error("Node#Info#filters does not include the 'normalization' Filter (Node has it not enable)");
503
- if (!this.data)
504
- this.data = {};
505
- if (!this.data.pluginFilters)
506
- this.data.pluginFilters = {};
507
- if (!this.data.pluginFilters.normalization)
508
- this.data.pluginFilters.normalization = {};
509
- if (this.filters.lavalinkLavaDspxPlugin.normalization) {
510
- delete this.data.pluginFilters.normalization;
511
- }
512
- else {
513
- this.data.pluginFilters.normalization = {
514
- adaptive: adaptive,
515
- maxAmplitude: maxAmplitude
516
- };
517
- }
518
- this.filters.lavalinkLavaDspxPlugin.normalization = !this.filters.lavalinkLavaDspxPlugin.normalization;
519
- await this.applyPlayerFilters();
520
- return this.filters.lavalinkLavaDspxPlugin.normalization;
521
- },
522
- /**
523
- * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
524
- * @param {number} [decay=0.5] - The decay of the echo effect.
525
- * @param {number} [echoLength=0.5] - The length of the echo effect.
526
- * @returns {Promise<boolean>} - The state of the filter after execution.
527
- */
528
- toggleEcho: async (decay = 0.5, echoLength = 0.5) => {
529
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavadspx-plugin"))
530
- throw new Error("Node#Info#plugins does not include the lavadspx plugin");
531
- if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
532
- throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable)");
533
- if (!this.data)
534
- this.data = {};
535
- if (!this.data.pluginFilters)
536
- this.data.pluginFilters = {};
537
- if (!this.data.pluginFilters.echo)
538
- this.data.pluginFilters.echo = {};
539
- if (this.filters.lavalinkLavaDspxPlugin.echo) {
540
- delete this.data.pluginFilters.echo;
541
- }
542
- else {
543
- this.data.pluginFilters.echo = {
544
- decay: decay,
545
- echoLength: echoLength
546
- };
547
- }
548
- this.filters.lavalinkLavaDspxPlugin.echo = !this.filters.lavalinkLavaDspxPlugin.echo;
549
- await this.applyPlayerFilters();
550
- return this.filters.lavalinkLavaDspxPlugin.echo;
551
- }
552
- };
553
- lavalinkFilterPlugin = {
554
- /**
555
- * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
556
- * @param delay
557
- * @param decay
558
- * @returns
559
- */
560
- toggleEcho: async (delay = 4, decay = 0.8) => {
561
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
562
- throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
563
- if (this.player.node.info && !this.player.node.info?.filters?.includes("echo"))
564
- throw new Error("Node#Info#filters does not include the 'echo' Filter (Node has it not enable aka not installed!)");
565
- if (!this.data)
566
- this.data = {};
567
- if (!this.data.pluginFilters)
568
- this.data.pluginFilters = {};
569
- if (!this.data.pluginFilters["lavalink-filter-plugin"])
570
- this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
571
- if (!this.data.pluginFilters["lavalink-filter-plugin"].echo)
572
- this.data.pluginFilters["lavalink-filter-plugin"].echo = { decay: 0, delay: 0 };
573
- this.data.pluginFilters["lavalink-filter-plugin"].echo.delay = this.filters.lavalinkFilterPlugin.echo ? 0 : delay;
574
- this.data.pluginFilters["lavalink-filter-plugin"].echo.decay = this.filters.lavalinkFilterPlugin.echo ? 0 : decay;
575
- this.filters.lavalinkFilterPlugin.echo = !this.filters.lavalinkFilterPlugin.echo;
576
- await this.applyPlayerFilters();
577
- return this.filters.lavalinkFilterPlugin.echo;
578
- },
579
- /**
580
- * Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
581
- * @param delays
582
- * @param gains
583
- * @returns
584
- */
585
- toggleReverb: async (delays = [0.037, 0.042, 0.048, 0.053], gains = [0.84, 0.83, 0.82, 0.81]) => {
586
- if (this.player.node.info && !this.player.node.info?.plugins?.find(v => v.name === "lavalink-filter-plugin"))
587
- throw new Error("Node#Info#plugins does not include the lavalink-filter-plugin plugin");
588
- if (this.player.node.info && !this.player.node.info?.filters?.includes("reverb"))
589
- throw new Error("Node#Info#filters does not include the 'reverb' Filter (Node has it not enable aka not installed!)");
590
- if (!this.data)
591
- this.data = {};
592
- if (!this.data.pluginFilters)
593
- this.data.pluginFilters = {};
594
- if (!this.data.pluginFilters["lavalink-filter-plugin"])
595
- this.data.pluginFilters["lavalink-filter-plugin"] = { echo: { decay: 0, delay: 0 }, reverb: { delays: [], gains: [] } };
596
- if (!this.data.pluginFilters["lavalink-filter-plugin"].reverb)
597
- this.data.pluginFilters["lavalink-filter-plugin"].reverb = { delays: [], gains: [] };
598
- this.data.pluginFilters["lavalink-filter-plugin"].reverb.delays = this.filters.lavalinkFilterPlugin.reverb ? [] : delays;
599
- this.data.pluginFilters["lavalink-filter-plugin"].reverb.gains = this.filters.lavalinkFilterPlugin.reverb ? [] : gains;
600
- this.filters.lavalinkFilterPlugin.reverb = !this.filters.lavalinkFilterPlugin.reverb;
601
- await this.applyPlayerFilters();
602
- return this.filters.lavalinkFilterPlugin.reverb;
603
- }
604
- };
605
- /**
606
- * Enables / Disables a Nightcore-like filter Effect. Disables/Overrides both: custom and Vaporwave Filter
607
- * @param speed
608
- * @param pitch
609
- * @param rate
610
- * @returns
611
- */
612
- async toggleNightcore(speed = 1.289999523162842, pitch = 1.289999523162842, rate = 0.9365999523162842) {
613
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
614
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
615
- this.data.timescale.speed = this.filters.nightcore ? 1 : speed;
616
- this.data.timescale.pitch = this.filters.nightcore ? 1 : pitch;
617
- this.data.timescale.rate = this.filters.nightcore ? 1 : rate;
618
- this.filters.nightcore = !this.filters.nightcore;
619
- this.filters.vaporwave = false;
620
- this.filters.custom = false;
621
- await this.applyPlayerFilters();
622
- return this.filters.nightcore;
623
- }
624
- /**
625
- * Enables / Disables a Vaporwave-like filter Effect. Disables/Overrides both: custom and nightcore Filter
626
- * @param speed
627
- * @param pitch
628
- * @param rate
629
- * @returns
630
- */
631
- async toggleVaporwave(speed = 0.8500000238418579, pitch = 0.800000011920929, rate = 1) {
632
- if (this.player.node.info && !this.player.node.info?.filters?.includes("timescale"))
633
- throw new Error("Node#Info#filters does not include the 'timescale' Filter (Node has it not enable)");
634
- this.data.timescale.speed = this.filters.vaporwave ? 1 : speed;
635
- this.data.timescale.pitch = this.filters.vaporwave ? 1 : pitch;
636
- this.data.timescale.rate = this.filters.vaporwave ? 1 : rate;
637
- this.filters.vaporwave = !this.filters.vaporwave;
638
- this.filters.nightcore = false;
639
- this.filters.custom = false;
640
- await this.applyPlayerFilters();
641
- return this.filters.vaporwave;
642
- }
643
- /**
644
- * Enable / Disables a Karaoke like Filter Effect
645
- * @param level
646
- * @param monoLevel
647
- * @param filterBand
648
- * @param filterWidth
649
- * @returns
650
- */
651
- async toggleKaraoke(level = 1, monoLevel = 1, filterBand = 220, filterWidth = 100) {
652
- if (this.player.node.info && !this.player.node.info?.filters?.includes("karaoke"))
653
- throw new Error("Node#Info#filters does not include the 'karaoke' Filter (Node has it not enable)");
654
- this.data.karaoke.level = this.filters.karaoke ? 0 : level;
655
- this.data.karaoke.monoLevel = this.filters.karaoke ? 0 : monoLevel;
656
- this.data.karaoke.filterBand = this.filters.karaoke ? 0 : filterBand;
657
- this.data.karaoke.filterWidth = this.filters.karaoke ? 0 : filterWidth;
658
- this.filters.karaoke = !this.filters.karaoke;
659
- await this.applyPlayerFilters();
660
- return this.filters.karaoke;
661
- }
662
- /** Function to find out if currently there is a custom timescamle etc. filter applied */
663
- isCustomFilterActive() {
664
- this.filters.custom = !this.filters.nightcore && !this.filters.vaporwave && Object.values(this.data.timescale).some(d => d !== 1);
665
- return this.filters.custom;
666
- }
667
- /**
668
- * Sets the players equalizer band on-top of the existing ones.
669
- * @param bands
670
- */
671
- async setEQ(bands) {
672
- if (!Array.isArray(bands))
673
- bands = [bands];
674
- if (!bands.length || !bands.every((band) => safeStringify(Object.keys(band).sort()) === '["band","gain"]'))
675
- throw new TypeError("Bands must be a non-empty object array containing 'band' and 'gain' properties.");
676
- for (const { band, gain } of bands)
677
- this.equalizerBands[band] = { band, gain };
678
- if (!this.player.node.sessionId)
679
- throw new Error("The Lavalink-Node is either not ready or not up to date");
680
- const now = performance.now();
681
- if (this.player.options.instaUpdateFiltersFix === true)
682
- this.filterUpdatedState = true;
683
- await this.player.node.updatePlayer({
684
- guildId: this.player.guildId,
685
- playerOptions: {
686
- filters: { equalizer: this.equalizerBands }
687
- }
688
- });
689
- this.player.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
690
- return this;
691
- }
692
- /** Clears the equalizer bands. */
693
- async clearEQ() {
694
- return this.setEQ(Array.from({ length: 15 }, (_v, i) => ({ band: i, gain: 0 })));
695
- }
696
- }