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