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,186 +0,0 @@
1
- import type { Track, UnresolvedTrack } from "./Types/Track.js";
2
- import type { ManagerQueueOptions, QueueStoreManager, StoredQueue } from "./Types/Queue.js";
3
- export declare class QueueSaver {
4
- /**
5
- * The queue store manager
6
- */
7
- private _;
8
- /**
9
- * The options for the queue saver
10
- */
11
- options: {
12
- maxPreviousTracks: number;
13
- };
14
- constructor(options: ManagerQueueOptions);
15
- /**
16
- * Get the queue for a guild
17
- * @param guildId The guild ID
18
- * @returns The queue for the guild
19
- */
20
- get(guildId: string): Promise<Partial<StoredQueue>>;
21
- /**
22
- * Delete the queue for a guild
23
- * @param guildId The guild ID
24
- * @returns The queue for the guild
25
- */
26
- delete(guildId: string): Promise<boolean | void>;
27
- /**
28
- * Set the queue for a guild
29
- * @param guildId The guild ID
30
- * @param valueToStringify The queue to set
31
- * @returns The queue for the guild
32
- */
33
- set(guildId: string, valueToStringify: StoredQueue): Promise<boolean | void>;
34
- /**
35
- * Sync the queue for a guild
36
- * @param guildId The guild ID
37
- * @returns The queue for the guild
38
- */
39
- sync(guildId: string): Promise<Partial<StoredQueue>>;
40
- }
41
- export declare class DefaultQueueStore implements QueueStoreManager {
42
- private data;
43
- constructor();
44
- /**
45
- * Get the queue for a guild
46
- * @param guildId The guild ID
47
- * @returns The queue for the guild
48
- */
49
- get(guildId: string): StoredQueue;
50
- /**
51
- * Set the queue for a guild
52
- * @param guildId The guild ID
53
- * @param valueToStringify The queue to set
54
- * @returns The queue for the guild
55
- */
56
- set(guildId: string, valueToStringify: any): boolean;
57
- /**
58
- * Delete the queue for a guild
59
- * @param guildId The guild ID
60
- * @returns The queue for the guild
61
- */
62
- delete(guildId: string): boolean;
63
- /**
64
- * Stringify the queue for a guild
65
- * @param value The queue to stringify
66
- * @returns The stringified queue
67
- */
68
- stringify(value: StoredQueue | string): StoredQueue | string;
69
- /**
70
- * Parse the queue for a guild
71
- * @param value The queue to parse
72
- * @returns The parsed queue
73
- */
74
- parse(value: StoredQueue | string): Partial<StoredQueue>;
75
- }
76
- export declare class Queue {
77
- readonly tracks: (Track | UnresolvedTrack)[];
78
- readonly previous: Track[];
79
- current: Track | null;
80
- options: {
81
- maxPreviousTracks: number;
82
- };
83
- private readonly guildId;
84
- private readonly QueueSaver;
85
- private managerUtils;
86
- private queueChanges;
87
- /**
88
- * Create a new Queue
89
- * @param guildId The guild ID
90
- * @param data The data to initialize the queue with
91
- * @param QueueSaver The queue saver to use
92
- * @param queueOptions
93
- */
94
- constructor(guildId: string, data?: Partial<StoredQueue>, QueueSaver?: QueueSaver, queueOptions?: ManagerQueueOptions);
95
- /**
96
- * Utils for a Queue
97
- */
98
- utils: {
99
- /**
100
- * Save the current cached Queue on the database/server (overides the server)
101
- */
102
- save: () => Promise<boolean | void>;
103
- /**
104
- * Sync the current queue database/server with the cached one
105
- * @returns {void}
106
- */
107
- sync: (override?: boolean, dontSyncCurrent?: boolean) => Promise<void>;
108
- destroy: () => Promise<boolean | void>;
109
- /**
110
- * @returns {{current:Track|null, previous:Track[], tracks:Track[]}}The Queue, but in a raw State, which allows easier handling for the QueueStoreManager
111
- */
112
- toJSON: () => StoredQueue;
113
- /**
114
- * Get the Total Duration of the Queue-Songs summed up
115
- * @returns {number}
116
- */
117
- totalDuration: () => number;
118
- };
119
- /**
120
- * Shuffles the current Queue, then saves it
121
- * @returns Amount of Tracks in the Queue
122
- */
123
- shuffle(): Promise<number>;
124
- /**
125
- * Add a Track to the Queue, and after saved in the "db" it returns the amount of the Tracks
126
- * @param {Track | Track[]} TrackOrTracks
127
- * @param {number} index At what position to add the Track
128
- * @returns {number} Queue-Size (for the next Tracks)
129
- */
130
- add(TrackOrTracks: Track | UnresolvedTrack | (Track | UnresolvedTrack)[], index?: number): any;
131
- /**
132
- * Splice the tracks in the Queue
133
- * @param {number} index Where to remove the Track
134
- * @param {number} amount How many Tracks to remove?
135
- * @param {Track | Track[]} TrackOrTracks Want to Add more Tracks?
136
- * @returns {Track} Spliced Track
137
- */
138
- splice(index: number, amount: number, TrackOrTracks?: Track | UnresolvedTrack | (Track | UnresolvedTrack)[]): any;
139
- /**
140
- * Remove stuff from the queue.tracks array
141
- * - single Track | UnresolvedTrack
142
- * - multiple Track | UnresovedTrack
143
- * - at the index or multiple indexes
144
- * @param removeQueryTrack
145
- * @returns null (if nothing was removed) / { removed } where removed is an array with all removed elements
146
- *
147
- * @example
148
- * ```js
149
- * // remove single track
150
- *
151
- * const track = player.queue.tracks[4];
152
- * await player.queue.remove(track);
153
- *
154
- * // if you already have the index you can straight up pass it too
155
- * await player.queue.remove(4);
156
- *
157
- *
158
- * // if you want to remove multiple tracks, e.g. from position 4 to position 10 you can do smt like this
159
- * await player.queue.remove(player.queue.tracks.slice(4, 10)) // get's the tracks from 4 - 10, which then get's found in the remove function to be removed
160
- *
161
- * // I still highly suggest to use .splice!
162
- *
163
- * await player.queue.splice(4, 10); // removes at index 4, 10 tracks
164
- *
165
- * await player.queue.splice(1, 1); // removes at index 1, 1 track
166
- *
167
- * await player.queue.splice(4, 0, ...tracks) // removes 0 tracks at position 4, and then inserts all tracks after position 4.
168
- * ```
169
- */
170
- remove<T extends Track | UnresolvedTrack | number | Track[] | UnresolvedTrack[] | number[] | (number | Track | UnresolvedTrack)[]>(removeQueryTrack: T): Promise<{
171
- removed: (Track | UnresolvedTrack)[];
172
- } | null>;
173
- /**
174
- * Shifts the previous array, to return the last previous track & thus remove it from the previous queue
175
- * @returns
176
- *
177
- * @example
178
- * ```js
179
- * // example on how to play the previous track again
180
- * const previous = await player.queue.shiftPrevious(); // get the previous track and remove it from the previous queue array!!
181
- * if(!previous) return console.error("No previous track found");
182
- * await player.play({ clientTrack: previous }); // play it again
183
- * ```
184
- */
185
- shiftPrevious(): Promise<Track>;
186
- }
@@ -1,384 +0,0 @@
1
- import { ManagerUtils, MiniMap, QueueSymbol } from "./Utils.js";
2
- export class QueueSaver {
3
- /**
4
- * The queue store manager
5
- */
6
- _;
7
- /**
8
- * The options for the queue saver
9
- */
10
- options;
11
- constructor(options) {
12
- this._ = options?.queueStore || new DefaultQueueStore();
13
- this.options = {
14
- maxPreviousTracks: options?.maxPreviousTracks || 25,
15
- };
16
- }
17
- /**
18
- * Get the queue for a guild
19
- * @param guildId The guild ID
20
- * @returns The queue for the guild
21
- */
22
- async get(guildId) {
23
- return this._.parse(await this._.get(guildId));
24
- }
25
- /**
26
- * Delete the queue for a guild
27
- * @param guildId The guild ID
28
- * @returns The queue for the guild
29
- */
30
- async delete(guildId) {
31
- return this._.delete(guildId);
32
- }
33
- /**
34
- * Set the queue for a guild
35
- * @param guildId The guild ID
36
- * @param valueToStringify The queue to set
37
- * @returns The queue for the guild
38
- */
39
- async set(guildId, valueToStringify) {
40
- return this._.set(guildId, await this._.stringify(valueToStringify));
41
- }
42
- /**
43
- * Sync the queue for a guild
44
- * @param guildId The guild ID
45
- * @returns The queue for the guild
46
- */
47
- async sync(guildId) {
48
- return this.get(guildId);
49
- }
50
- }
51
- export class DefaultQueueStore {
52
- data = new MiniMap();
53
- constructor() { }
54
- /**
55
- * Get the queue for a guild
56
- * @param guildId The guild ID
57
- * @returns The queue for the guild
58
- */
59
- get(guildId) {
60
- return this.data.get(guildId);
61
- }
62
- /**
63
- * Set the queue for a guild
64
- * @param guildId The guild ID
65
- * @param valueToStringify The queue to set
66
- * @returns The queue for the guild
67
- */
68
- set(guildId, valueToStringify) {
69
- return this.data.set(guildId, valueToStringify) ? true : false;
70
- }
71
- /**
72
- * Delete the queue for a guild
73
- * @param guildId The guild ID
74
- * @returns The queue for the guild
75
- */
76
- delete(guildId) {
77
- return this.data.delete(guildId);
78
- }
79
- /**
80
- * Stringify the queue for a guild
81
- * @param value The queue to stringify
82
- * @returns The stringified queue
83
- */
84
- stringify(value) {
85
- return value; // JSON.stringify(value);
86
- }
87
- /**
88
- * Parse the queue for a guild
89
- * @param value The queue to parse
90
- * @returns The parsed queue
91
- */
92
- parse(value) {
93
- return value; // JSON.parse(value)
94
- }
95
- }
96
- export class Queue {
97
- tracks = [];
98
- previous = [];
99
- current = null;
100
- options = { maxPreviousTracks: 25 };
101
- guildId = "";
102
- QueueSaver = null;
103
- managerUtils = new ManagerUtils();
104
- queueChanges;
105
- /**
106
- * Create a new Queue
107
- * @param guildId The guild ID
108
- * @param data The data to initialize the queue with
109
- * @param QueueSaver The queue saver to use
110
- * @param queueOptions
111
- */
112
- constructor(guildId, data = {}, QueueSaver, queueOptions) {
113
- this.queueChanges = queueOptions.queueChangesWatcher || null;
114
- this.guildId = guildId;
115
- this.QueueSaver = QueueSaver;
116
- this.options.maxPreviousTracks = this.QueueSaver?.options?.maxPreviousTracks ?? this.options.maxPreviousTracks;
117
- this.current = this.managerUtils.isTrack(data.current) ? data.current : null;
118
- this.previous = Array.isArray(data.previous) && data.previous.some(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)) ? data.previous.filter(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)) : [];
119
- this.tracks = Array.isArray(data.tracks) && data.tracks.some(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)) ? data.tracks.filter(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)) : [];
120
- Object.defineProperty(this, QueueSymbol, { configurable: true, value: true });
121
- }
122
- /**
123
- * Utils for a Queue
124
- */
125
- utils = {
126
- /**
127
- * Save the current cached Queue on the database/server (overides the server)
128
- */
129
- save: async () => {
130
- if (this.previous.length > this.options.maxPreviousTracks)
131
- this.previous.splice(this.options.maxPreviousTracks, this.previous.length);
132
- return await this.QueueSaver.set(this.guildId, this.utils.toJSON());
133
- },
134
- /**
135
- * Sync the current queue database/server with the cached one
136
- * @returns {void}
137
- */
138
- sync: async (override = true, dontSyncCurrent = true) => {
139
- const data = await this.QueueSaver.get(this.guildId);
140
- if (!data)
141
- throw new Error(`No data found to sync for guildId: ${this.guildId}`);
142
- if (!dontSyncCurrent && !this.current && (this.managerUtils.isTrack(data.current)))
143
- this.current = data.current;
144
- if (Array.isArray(data.tracks) && data?.tracks.length && data.tracks.some(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)))
145
- this.tracks.splice(override ? 0 : this.tracks.length, override ? this.tracks.length : 0, ...data.tracks.filter(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)));
146
- if (Array.isArray(data.previous) && data?.previous.length && data.previous.some(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)))
147
- this.previous.splice(0, override ? this.tracks.length : 0, ...data.previous.filter(track => this.managerUtils.isTrack(track) || this.managerUtils.isUnresolvedTrack(track)));
148
- await this.utils.save();
149
- return;
150
- },
151
- destroy: async () => {
152
- return await this.QueueSaver.delete(this.guildId);
153
- },
154
- /**
155
- * @returns {{current:Track|null, previous:Track[], tracks:Track[]}}The Queue, but in a raw State, which allows easier handling for the QueueStoreManager
156
- */
157
- toJSON: () => {
158
- if (this.previous.length > this.options.maxPreviousTracks)
159
- this.previous.splice(this.options.maxPreviousTracks, this.previous.length);
160
- return {
161
- current: this.current ? { ...this.current } : null,
162
- previous: this.previous ? [...this.previous] : [],
163
- tracks: this.tracks ? [...this.tracks] : [],
164
- };
165
- },
166
- /**
167
- * Get the Total Duration of the Queue-Songs summed up
168
- * @returns {number}
169
- */
170
- totalDuration: () => {
171
- return this.tracks.reduce((acc, cur) => acc + (cur.info.duration || 0), this.current?.info.duration || 0);
172
- }
173
- };
174
- /**
175
- * Shuffles the current Queue, then saves it
176
- * @returns Amount of Tracks in the Queue
177
- */
178
- async shuffle() {
179
- const oldStored = typeof this.queueChanges?.shuffled === "function" ? this.utils.toJSON() : null;
180
- if (this.tracks.length <= 1)
181
- return this.tracks.length;
182
- // swap #1 and #2 if only 2 tracks.
183
- if (this.tracks.length === 2) {
184
- [this.tracks[0], this.tracks[1]] = [this.tracks[1], this.tracks[0]];
185
- }
186
- else { // randomly swap places.
187
- for (let i = this.tracks.length - 1; i > 0; i--) {
188
- const j = Math.floor(Math.random() * (i + 1));
189
- [this.tracks[i], this.tracks[j]] = [this.tracks[j], this.tracks[i]];
190
- }
191
- }
192
- // LOG
193
- if (typeof this.queueChanges?.shuffled === "function")
194
- this.queueChanges.shuffled(this.guildId, oldStored, this.utils.toJSON());
195
- await this.utils.save();
196
- return this.tracks.length;
197
- }
198
- /**
199
- * Add a Track to the Queue, and after saved in the "db" it returns the amount of the Tracks
200
- * @param {Track | Track[]} TrackOrTracks
201
- * @param {number} index At what position to add the Track
202
- * @returns {number} Queue-Size (for the next Tracks)
203
- */
204
- async add(TrackOrTracks, index) {
205
- if (typeof index === "number" && index >= 0 && index < this.tracks.length) {
206
- return await this.splice(index, 0, (Array.isArray(TrackOrTracks) ? TrackOrTracks : [TrackOrTracks]).flat(2).filter(v => this.managerUtils.isTrack(v) || this.managerUtils.isUnresolvedTrack(v)));
207
- }
208
- const oldStored = typeof this.queueChanges?.tracksAdd === "function" ? this.utils.toJSON() : null;
209
- // add the track(s)
210
- this.tracks.push(...(Array.isArray(TrackOrTracks) ? TrackOrTracks : [TrackOrTracks]).flat(2).filter(v => this.managerUtils.isTrack(v) || this.managerUtils.isUnresolvedTrack(v)));
211
- // log if available
212
- if (typeof this.queueChanges?.tracksAdd === "function")
213
- try {
214
- this.queueChanges.tracksAdd(this.guildId, (Array.isArray(TrackOrTracks) ? TrackOrTracks : [TrackOrTracks]).flat(2).filter(v => this.managerUtils.isTrack(v) || this.managerUtils.isUnresolvedTrack(v)), this.tracks.length, oldStored, this.utils.toJSON());
215
- }
216
- catch { /* */ }
217
- // save the queue
218
- await this.utils.save();
219
- // return the amount of the tracks
220
- return this.tracks.length;
221
- }
222
- /**
223
- * Splice the tracks in the Queue
224
- * @param {number} index Where to remove the Track
225
- * @param {number} amount How many Tracks to remove?
226
- * @param {Track | Track[]} TrackOrTracks Want to Add more Tracks?
227
- * @returns {Track} Spliced Track
228
- */
229
- async splice(index, amount, TrackOrTracks) {
230
- const oldStored = typeof this.queueChanges?.tracksAdd === "function" || typeof this.queueChanges?.tracksRemoved === "function" ? this.utils.toJSON() : null;
231
- // if no tracks to splice, add the tracks
232
- if (!this.tracks.length) {
233
- if (TrackOrTracks)
234
- return await this.add(TrackOrTracks);
235
- return null;
236
- }
237
- // Log if available
238
- if ((TrackOrTracks) && typeof this.queueChanges?.tracksAdd === "function")
239
- try {
240
- this.queueChanges.tracksAdd(this.guildId, (Array.isArray(TrackOrTracks) ? TrackOrTracks : [TrackOrTracks]).flat(2).filter(v => this.managerUtils.isTrack(v) || this.managerUtils.isUnresolvedTrack(v)), index, oldStored, this.utils.toJSON());
241
- }
242
- catch { /* */ }
243
- // remove the tracks (and add the new ones)
244
- let spliced = TrackOrTracks ? this.tracks.splice(index, amount, ...(Array.isArray(TrackOrTracks) ? TrackOrTracks : [TrackOrTracks]).flat(2).filter(v => this.managerUtils.isTrack(v) || this.managerUtils.isUnresolvedTrack(v))) : this.tracks.splice(index, amount);
245
- // get the spliced array
246
- spliced = (Array.isArray(spliced) ? spliced : [spliced]);
247
- // Log if available
248
- if (typeof this.queueChanges?.tracksRemoved === "function")
249
- try {
250
- this.queueChanges.tracksRemoved(this.guildId, spliced, index, oldStored, this.utils.toJSON());
251
- }
252
- catch { /* */ }
253
- // save the queue
254
- await this.utils.save();
255
- // return the things
256
- return spliced.length === 1 ? spliced[0] : spliced;
257
- }
258
- /**
259
- * Remove stuff from the queue.tracks array
260
- * - single Track | UnresolvedTrack
261
- * - multiple Track | UnresovedTrack
262
- * - at the index or multiple indexes
263
- * @param removeQueryTrack
264
- * @returns null (if nothing was removed) / { removed } where removed is an array with all removed elements
265
- *
266
- * @example
267
- * ```js
268
- * // remove single track
269
- *
270
- * const track = player.queue.tracks[4];
271
- * await player.queue.remove(track);
272
- *
273
- * // if you already have the index you can straight up pass it too
274
- * await player.queue.remove(4);
275
- *
276
- *
277
- * // if you want to remove multiple tracks, e.g. from position 4 to position 10 you can do smt like this
278
- * await player.queue.remove(player.queue.tracks.slice(4, 10)) // get's the tracks from 4 - 10, which then get's found in the remove function to be removed
279
- *
280
- * // I still highly suggest to use .splice!
281
- *
282
- * await player.queue.splice(4, 10); // removes at index 4, 10 tracks
283
- *
284
- * await player.queue.splice(1, 1); // removes at index 1, 1 track
285
- *
286
- * await player.queue.splice(4, 0, ...tracks) // removes 0 tracks at position 4, and then inserts all tracks after position 4.
287
- * ```
288
- */
289
- async remove(removeQueryTrack) {
290
- const oldStored = typeof this.queueChanges?.tracksRemoved === "function" ? this.utils.toJSON() : null;
291
- if (typeof removeQueryTrack === "number") {
292
- const toRemove = this.tracks[removeQueryTrack];
293
- if (!toRemove)
294
- return null;
295
- const removed = this.tracks.splice(removeQueryTrack, 1);
296
- // Log if available
297
- if (typeof this.queueChanges?.tracksRemoved === "function")
298
- try {
299
- this.queueChanges.tracksRemoved(this.guildId, removed, removeQueryTrack, oldStored, this.utils.toJSON());
300
- }
301
- catch { /* */ }
302
- await this.utils.save();
303
- return { removed };
304
- }
305
- if (Array.isArray(removeQueryTrack)) {
306
- if (removeQueryTrack.every(v => typeof v === "number")) {
307
- const removed = [];
308
- for (const i of removeQueryTrack) {
309
- if (this.tracks[i]) {
310
- removed.push(...this.tracks.splice(i, 1));
311
- }
312
- }
313
- if (!removed.length)
314
- return null;
315
- // Log if available
316
- if (typeof this.queueChanges?.tracksRemoved === "function")
317
- try {
318
- this.queueChanges.tracksRemoved(this.guildId, removed, removeQueryTrack, oldStored, this.utils.toJSON());
319
- }
320
- catch { /* */ }
321
- await this.utils.save();
322
- return { removed };
323
- }
324
- const tracksToRemove = this.tracks.map((v, i) => ({ v, i })).filter(({ v, i }) => removeQueryTrack.find(t => typeof t === "number" && (t === i) ||
325
- typeof t === "object" && (t.encoded && t.encoded === v.encoded ||
326
- t.info?.identifier && t.info.identifier === v.info?.identifier ||
327
- t.info?.uri && t.info.uri === v.info?.uri ||
328
- t.info?.title && t.info.title === v.info?.title ||
329
- t.info?.isrc && t.info.isrc === v.info?.isrc ||
330
- t.info?.artworkUrl && t.info.artworkUrl === v.info?.artworkUrl)));
331
- if (!tracksToRemove.length)
332
- return null;
333
- const removed = [];
334
- for (const { i } of tracksToRemove) {
335
- if (this.tracks[i]) {
336
- removed.push(...this.tracks.splice(i, 1));
337
- }
338
- }
339
- // Log if available
340
- if (typeof this.queueChanges?.tracksRemoved === "function")
341
- try {
342
- this.queueChanges.tracksRemoved(this.guildId, removed, tracksToRemove.map(v => v.i), oldStored, this.utils.toJSON());
343
- }
344
- catch { /* */ }
345
- await this.utils.save();
346
- return { removed };
347
- }
348
- const toRemove = this.tracks.findIndex((v) => removeQueryTrack.encoded && removeQueryTrack.encoded === v.encoded ||
349
- removeQueryTrack.info?.identifier && removeQueryTrack.info.identifier === v.info?.identifier ||
350
- removeQueryTrack.info?.uri && removeQueryTrack.info.uri === v.info?.uri ||
351
- removeQueryTrack.info?.title && removeQueryTrack.info.title === v.info?.title ||
352
- removeQueryTrack.info?.isrc && removeQueryTrack.info.isrc === v.info?.isrc ||
353
- removeQueryTrack.info?.artworkUrl && removeQueryTrack.info.artworkUrl === v.info?.artworkUrl);
354
- if (toRemove < 0)
355
- return null;
356
- const removed = this.tracks.splice(toRemove, 1);
357
- // Log if available
358
- if (typeof this.queueChanges?.tracksRemoved === "function")
359
- try {
360
- this.queueChanges.tracksRemoved(this.guildId, removed, toRemove, oldStored, this.utils.toJSON());
361
- }
362
- catch { /* */ }
363
- await this.utils.save();
364
- return { removed };
365
- }
366
- /**
367
- * Shifts the previous array, to return the last previous track & thus remove it from the previous queue
368
- * @returns
369
- *
370
- * @example
371
- * ```js
372
- * // example on how to play the previous track again
373
- * const previous = await player.queue.shiftPrevious(); // get the previous track and remove it from the previous queue array!!
374
- * if(!previous) return console.error("No previous track found");
375
- * await player.play({ clientTrack: previous }); // play it again
376
- * ```
377
- */
378
- async shiftPrevious() {
379
- const removed = this.previous.shift();
380
- if (removed)
381
- await this.utils.save();
382
- return removed ?? null;
383
- }
384
- }