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