magmastream 2.9.3-dev.3 → 2.9.3-dev.31
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/dist/config/blockedWords.d.ts +1 -0
- package/dist/index.d.ts +19 -3687
- package/dist/index.js +1 -1
- package/dist/statestorage/JsonQueue.d.ts +173 -0
- package/dist/statestorage/JsonQueue.js +32 -4
- package/dist/statestorage/MemoryQueue.d.ts +154 -0
- package/dist/statestorage/MemoryQueue.js +56 -36
- package/dist/statestorage/RedisQueue.d.ts +178 -0
- package/dist/statestorage/RedisQueue.js +29 -7
- package/dist/structures/Enums.d.ts +310 -0
- package/dist/structures/Enums.js +6 -0
- package/dist/structures/Filters.d.ts +352 -0
- package/dist/structures/Filters.js +5 -4
- package/dist/structures/MagmastreamError.d.ts +14 -0
- package/dist/structures/Manager.d.ts +259 -0
- package/dist/structures/Manager.js +296 -555
- package/dist/structures/Node.d.ts +390 -0
- package/dist/structures/Node.js +100 -145
- package/dist/structures/Player.d.ts +347 -0
- package/dist/structures/Player.js +55 -132
- package/dist/structures/Plugin.d.ts +23 -0
- package/dist/structures/Rest.d.ts +93 -0
- package/dist/structures/Rest.js +41 -21
- package/dist/structures/Types.d.ts +1315 -0
- package/dist/structures/Utils.d.ts +169 -0
- package/dist/structures/Utils.js +145 -71
- package/dist/utils/filtersEqualizers.d.ts +16 -0
- package/dist/utils/managerCheck.d.ts +7 -0
- package/dist/utils/nodeCheck.d.ts +7 -0
- package/dist/utils/playerCheck.d.ts +7 -0
- package/dist/wrappers/discord.js.d.ts +15 -0
- package/dist/wrappers/discord.js.js +19 -4
- package/dist/wrappers/discordeno.d.ts +19 -0
- package/dist/wrappers/discordeno.js +77 -0
- package/dist/wrappers/eris.d.ts +15 -0
- package/dist/wrappers/eris.js +20 -3
- package/dist/wrappers/oceanic.d.ts +15 -0
- package/dist/wrappers/oceanic.js +22 -4
- package/dist/wrappers/seyfert.d.ts +37 -0
- package/dist/wrappers/seyfert.js +25 -1
- package/package.json +106 -98
- package/dist/wrappers/detritus.js +0 -52
package/dist/index.js
CHANGED
|
@@ -11,9 +11,9 @@ tslib_1.__exportStar(require("./structures/Rest"), exports);
|
|
|
11
11
|
tslib_1.__exportStar(require("./structures/Utils"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./structures/MagmastreamError"), exports);
|
|
13
13
|
// wrappers
|
|
14
|
+
tslib_1.__exportStar(require("./wrappers/discordeno"), exports);
|
|
14
15
|
tslib_1.__exportStar(require("./wrappers/discord.js"), exports);
|
|
15
16
|
tslib_1.__exportStar(require("./wrappers/eris"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./wrappers/detritus"), exports);
|
|
17
17
|
tslib_1.__exportStar(require("./wrappers/oceanic"), exports);
|
|
18
18
|
tslib_1.__exportStar(require("./wrappers/seyfert"), exports);
|
|
19
19
|
// types
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Manager } from "../structures/Manager";
|
|
2
|
+
import { IQueue, Track } from "../structures/Types";
|
|
3
|
+
/**
|
|
4
|
+
* The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
|
|
5
|
+
*/
|
|
6
|
+
export declare class JsonQueue implements IQueue {
|
|
7
|
+
readonly guildId: string;
|
|
8
|
+
readonly manager: Manager;
|
|
9
|
+
/**
|
|
10
|
+
* The base path for the queue files.
|
|
11
|
+
*/
|
|
12
|
+
private basePath;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the queue has been destroyed.
|
|
15
|
+
*/
|
|
16
|
+
private destroyed;
|
|
17
|
+
/**
|
|
18
|
+
* @param guildId The guild ID.
|
|
19
|
+
* @param manager The manager.
|
|
20
|
+
*/
|
|
21
|
+
constructor(guildId: string, manager: Manager);
|
|
22
|
+
/**
|
|
23
|
+
* @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
|
|
24
|
+
* @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
|
|
25
|
+
*/
|
|
26
|
+
add(track: Track | Track[], offset?: number): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* @param track The track to add.
|
|
29
|
+
*/
|
|
30
|
+
addPrevious(track: Track | Track[]): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Clears the queue.
|
|
33
|
+
*/
|
|
34
|
+
clear(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Clears the previous tracks.
|
|
37
|
+
*/
|
|
38
|
+
clearPrevious(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Removes the first track from the queue.
|
|
41
|
+
*/
|
|
42
|
+
dequeue(): Promise<Track | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Destroys the queue and releases all resources.
|
|
45
|
+
* After calling this method, the queue must not be used again.
|
|
46
|
+
*/
|
|
47
|
+
destroy(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* @returns The total duration of the queue.
|
|
50
|
+
*/
|
|
51
|
+
duration(): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a track to the front of the queue.
|
|
54
|
+
*/
|
|
55
|
+
enqueueFront(track: Track | Track[]): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Tests whether all elements in the queue pass the test implemented by the provided function.
|
|
58
|
+
*/
|
|
59
|
+
everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Filters the queue.
|
|
62
|
+
*/
|
|
63
|
+
filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Finds the first track in the queue that satisfies the provided testing function.
|
|
66
|
+
*/
|
|
67
|
+
findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* @returns The current track.
|
|
70
|
+
*/
|
|
71
|
+
getCurrent(): Promise<Track | null>;
|
|
72
|
+
/**
|
|
73
|
+
* @returns The previous tracks.
|
|
74
|
+
*/
|
|
75
|
+
getPrevious(): Promise<Track[]>;
|
|
76
|
+
/**
|
|
77
|
+
* @returns The tracks in the queue from start to end.
|
|
78
|
+
*/
|
|
79
|
+
getSlice(start?: number, end?: number): Promise<Track[]>;
|
|
80
|
+
/**
|
|
81
|
+
* @returns The tracks in the queue.
|
|
82
|
+
*/
|
|
83
|
+
getTracks(): Promise<Track[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Maps the queue to a new array.
|
|
86
|
+
*/
|
|
87
|
+
mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Modifies the queue at the specified index.
|
|
90
|
+
*/
|
|
91
|
+
modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
|
|
92
|
+
/**
|
|
93
|
+
* @returns The newest track.
|
|
94
|
+
*/
|
|
95
|
+
popPrevious(): Promise<Track | null>;
|
|
96
|
+
/**
|
|
97
|
+
* Removes a track from the queue.
|
|
98
|
+
* @param position The position to remove the track at.
|
|
99
|
+
* @param end The end position to remove the track at.
|
|
100
|
+
*/
|
|
101
|
+
remove(position?: number): Promise<Track[]>;
|
|
102
|
+
remove(start: number, end: number): Promise<Track[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Shuffles the queue by round-robin.
|
|
105
|
+
*/
|
|
106
|
+
roundRobinShuffle(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* @param track The track to set.
|
|
109
|
+
*/
|
|
110
|
+
setCurrent(track: Track | null): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* @param track The track to set.
|
|
113
|
+
*/
|
|
114
|
+
setPrevious(track: Track | Track[]): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Shuffles the queue.
|
|
117
|
+
*/
|
|
118
|
+
shuffle(): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* @returns The size of the queue.
|
|
121
|
+
*/
|
|
122
|
+
size(): Promise<number>;
|
|
123
|
+
/**
|
|
124
|
+
* Tests whether at least one element in the queue passes the test implemented by the provided function.
|
|
125
|
+
*/
|
|
126
|
+
someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* @returns The total size of the queue.
|
|
129
|
+
*/
|
|
130
|
+
totalSize(): Promise<number>;
|
|
131
|
+
/**
|
|
132
|
+
* Shuffles the queue by user.
|
|
133
|
+
*/
|
|
134
|
+
userBlockShuffle(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* @returns The current path.
|
|
137
|
+
*/
|
|
138
|
+
private get currentPath();
|
|
139
|
+
/**
|
|
140
|
+
* @param filePath The file path.
|
|
141
|
+
*/
|
|
142
|
+
private deleteFile;
|
|
143
|
+
/**
|
|
144
|
+
* Ensures the directory exists.
|
|
145
|
+
*/
|
|
146
|
+
private ensureDir;
|
|
147
|
+
/**
|
|
148
|
+
* @returns The queue.
|
|
149
|
+
*/
|
|
150
|
+
private getQueue;
|
|
151
|
+
/**
|
|
152
|
+
* @returns The previous path.
|
|
153
|
+
*/
|
|
154
|
+
private get previousPath();
|
|
155
|
+
/**
|
|
156
|
+
* @returns The queue path.
|
|
157
|
+
*/
|
|
158
|
+
private get queuePath();
|
|
159
|
+
/**
|
|
160
|
+
* @param filePath The file path.
|
|
161
|
+
* @returns The JSON data.
|
|
162
|
+
*/
|
|
163
|
+
private readJSON;
|
|
164
|
+
/**
|
|
165
|
+
* @param queue The queue.
|
|
166
|
+
*/
|
|
167
|
+
private setQueue;
|
|
168
|
+
/**
|
|
169
|
+
* @param filePath The file path.
|
|
170
|
+
* @param data The data to write.
|
|
171
|
+
*/
|
|
172
|
+
private writeJSON;
|
|
173
|
+
}
|
|
@@ -17,6 +17,10 @@ class JsonQueue {
|
|
|
17
17
|
* The base path for the queue files.
|
|
18
18
|
*/
|
|
19
19
|
basePath;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the queue has been destroyed.
|
|
22
|
+
*/
|
|
23
|
+
destroyed = false;
|
|
20
24
|
/**
|
|
21
25
|
* @param guildId The guild ID.
|
|
22
26
|
* @param manager The manager.
|
|
@@ -98,8 +102,11 @@ class JsonQueue {
|
|
|
98
102
|
const tracks = Array.isArray(track) ? track : [track];
|
|
99
103
|
if (!tracks.length)
|
|
100
104
|
return;
|
|
101
|
-
const current = await this.getPrevious();
|
|
102
|
-
const
|
|
105
|
+
const current = (await this.getPrevious()).filter((p) => p !== null);
|
|
106
|
+
const validTracks = tracks.filter((t) => t !== null && typeof t.uri === "string");
|
|
107
|
+
if (!validTracks.length)
|
|
108
|
+
return;
|
|
109
|
+
const newTracks = validTracks.filter((t) => !current.some((p) => p.uri === t.uri));
|
|
103
110
|
if (!newTracks.length)
|
|
104
111
|
return;
|
|
105
112
|
const updated = [...current, ...newTracks];
|
|
@@ -172,6 +179,27 @@ class JsonQueue {
|
|
|
172
179
|
console.error(error);
|
|
173
180
|
}
|
|
174
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Destroys the queue and releases all resources.
|
|
184
|
+
* After calling this method, the queue must not be used again.
|
|
185
|
+
*/
|
|
186
|
+
async destroy() {
|
|
187
|
+
if (this.destroyed)
|
|
188
|
+
return;
|
|
189
|
+
this.destroyed = true;
|
|
190
|
+
try {
|
|
191
|
+
await Promise.all([this.deleteFile(this.queuePath), this.deleteFile(this.currentPath), this.deleteFile(this.previousPath)]);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
console.error(err instanceof MagmastreamError_1.MagmaStreamError
|
|
195
|
+
? err
|
|
196
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
197
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
198
|
+
message: `Failed to destroy JSONQueue for guild ${this.guildId}`,
|
|
199
|
+
cause: err,
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
175
203
|
/**
|
|
176
204
|
* @returns The total duration of the queue.
|
|
177
205
|
*/
|
|
@@ -348,7 +376,7 @@ class JsonQueue {
|
|
|
348
376
|
const queue = await this.getQueue();
|
|
349
377
|
const userMap = new Map();
|
|
350
378
|
for (const track of queue) {
|
|
351
|
-
const userId = track.requester.id;
|
|
379
|
+
const userId = track.requester.id.toString();
|
|
352
380
|
if (!userMap.has(userId))
|
|
353
381
|
userMap.set(userId, []);
|
|
354
382
|
userMap.get(userId).push(track);
|
|
@@ -473,7 +501,7 @@ class JsonQueue {
|
|
|
473
501
|
const queue = await this.getQueue();
|
|
474
502
|
const userMap = new Map();
|
|
475
503
|
for (const track of queue) {
|
|
476
|
-
const userId = track.requester.id;
|
|
504
|
+
const userId = track.requester.id.toString();
|
|
477
505
|
if (!userMap.has(userId))
|
|
478
506
|
userMap.set(userId, []);
|
|
479
507
|
userMap.get(userId).push(track);
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Manager } from "../structures/Manager";
|
|
2
|
+
import { IQueue, Track } from "../structures/Types";
|
|
3
|
+
/**
|
|
4
|
+
* The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryQueue extends Array<Track> implements IQueue {
|
|
7
|
+
/** The current track */
|
|
8
|
+
current: Track | null;
|
|
9
|
+
/** The previous tracks */
|
|
10
|
+
previous: Track[];
|
|
11
|
+
/** The Manager instance. */
|
|
12
|
+
manager: Manager;
|
|
13
|
+
/** The guild ID property. */
|
|
14
|
+
guildId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the queue has been destroyed.
|
|
17
|
+
*/
|
|
18
|
+
private destroyed;
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new Queue.
|
|
21
|
+
* @param guildId The guild ID.
|
|
22
|
+
* @param manager The Manager instance.
|
|
23
|
+
*/
|
|
24
|
+
constructor(guildId: string, manager: Manager);
|
|
25
|
+
/**
|
|
26
|
+
* Adds a track to the queue.
|
|
27
|
+
* @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
|
|
28
|
+
* @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
|
|
29
|
+
*/
|
|
30
|
+
add(track: Track | Track[], offset?: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Adds a track to the previous tracks.
|
|
33
|
+
* @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
|
|
34
|
+
*/
|
|
35
|
+
addPrevious(track: Track | Track[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Clears the queue.
|
|
38
|
+
* This will remove all tracks from the queue and emit a state update event.
|
|
39
|
+
*/
|
|
40
|
+
clear(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Clears the previous tracks.
|
|
43
|
+
*/
|
|
44
|
+
clearPrevious(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Removes the first element from the queue.
|
|
47
|
+
*/
|
|
48
|
+
dequeue(): Track | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Destroys the queue and releases all resources.
|
|
51
|
+
* After calling this method, the queue must not be used again.
|
|
52
|
+
*/
|
|
53
|
+
destroy(): void;
|
|
54
|
+
/**
|
|
55
|
+
* The total duration of the queue in milliseconds.
|
|
56
|
+
* This includes the duration of the currently playing track.
|
|
57
|
+
*/
|
|
58
|
+
duration(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Adds the specified track or tracks to the front of the queue.
|
|
61
|
+
* @param track The track or tracks to add.
|
|
62
|
+
*/
|
|
63
|
+
enqueueFront(track: Track | Track[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* @returns Whether all elements in the queue satisfy the provided testing function.
|
|
66
|
+
*/
|
|
67
|
+
everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* @returns A new array with all elements that pass the test implemented by the provided function.
|
|
70
|
+
*/
|
|
71
|
+
filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track[];
|
|
72
|
+
/**
|
|
73
|
+
* @returns The first element in the queue that satisfies the provided testing function.
|
|
74
|
+
*/
|
|
75
|
+
findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* @returns The current track.
|
|
78
|
+
*/
|
|
79
|
+
getCurrent(): Track | null;
|
|
80
|
+
/**
|
|
81
|
+
* @returns The previous tracks.
|
|
82
|
+
*/
|
|
83
|
+
getPrevious(): Track[];
|
|
84
|
+
/**
|
|
85
|
+
* @returns The tracks in the queue from start to end.
|
|
86
|
+
*/
|
|
87
|
+
getSlice(start?: number, end?: number): Track[];
|
|
88
|
+
/**
|
|
89
|
+
* @returns The tracks in the queue.
|
|
90
|
+
*/
|
|
91
|
+
getTracks(): Track[];
|
|
92
|
+
/**
|
|
93
|
+
* @returns A new array with the results of calling a provided function on every element in the queue.
|
|
94
|
+
*/
|
|
95
|
+
mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): T[];
|
|
96
|
+
/**
|
|
97
|
+
* Modifies the queue at the specified index.
|
|
98
|
+
* @param start The index at which to start modifying the queue.
|
|
99
|
+
* @param deleteCount The number of elements to remove from the queue.
|
|
100
|
+
* @param items The elements to add to the queue.
|
|
101
|
+
* @returns The modified queue.
|
|
102
|
+
*/
|
|
103
|
+
modifyAt(start: number, deleteCount?: number, ...items: Track[]): Track[];
|
|
104
|
+
/**
|
|
105
|
+
* @returns The newest track.
|
|
106
|
+
*/
|
|
107
|
+
popPrevious(): Track | null;
|
|
108
|
+
/**
|
|
109
|
+
* Removes track(s) from the queue.
|
|
110
|
+
* @param startOrPosition If a single number is provided, it will be treated as the position of the track to remove.
|
|
111
|
+
* If two numbers are provided, they will be used as the start and end of a range of tracks to remove.
|
|
112
|
+
* @param end Optional, end of the range of tracks to remove.
|
|
113
|
+
* @returns The removed track(s).
|
|
114
|
+
*/
|
|
115
|
+
remove(position?: number): Track[];
|
|
116
|
+
remove(start: number, end: number): Track[];
|
|
117
|
+
/**
|
|
118
|
+
* Shuffles the queue to play tracks requested by each user one by one.
|
|
119
|
+
*/
|
|
120
|
+
roundRobinShuffle(): void;
|
|
121
|
+
/**
|
|
122
|
+
* @param track The track to set.
|
|
123
|
+
*/
|
|
124
|
+
setCurrent(track: Track | null): void;
|
|
125
|
+
/**
|
|
126
|
+
* @param tracks The tracks to set.
|
|
127
|
+
*/
|
|
128
|
+
setPrevious(tracks: Track[]): void;
|
|
129
|
+
/**
|
|
130
|
+
* Shuffles the queue.
|
|
131
|
+
* This will randomize the order of the tracks in the queue and emit a state update event.
|
|
132
|
+
*/
|
|
133
|
+
shuffle(): void;
|
|
134
|
+
/**
|
|
135
|
+
* The size of tracks in the queue.
|
|
136
|
+
* This does not include the currently playing track.
|
|
137
|
+
* @returns The size of tracks in the queue.
|
|
138
|
+
*/
|
|
139
|
+
size(): number;
|
|
140
|
+
/**
|
|
141
|
+
* @returns Whether at least one element in the queue satisfies the provided testing function.
|
|
142
|
+
*/
|
|
143
|
+
someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* The total size of tracks in the queue including the current track.
|
|
146
|
+
* This includes the current track if it is not null.
|
|
147
|
+
* @returns The total size of tracks in the queue including the current track.
|
|
148
|
+
*/
|
|
149
|
+
totalSize(): number;
|
|
150
|
+
/**
|
|
151
|
+
* Shuffles the queue to play tracks requested by each user one block at a time.
|
|
152
|
+
*/
|
|
153
|
+
userBlockShuffle(): void;
|
|
154
|
+
}
|
|
@@ -16,6 +16,10 @@ class MemoryQueue extends Array {
|
|
|
16
16
|
manager;
|
|
17
17
|
/** The guild ID property. */
|
|
18
18
|
guildId;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the queue has been destroyed.
|
|
21
|
+
*/
|
|
22
|
+
destroyed = false;
|
|
19
23
|
/**
|
|
20
24
|
* Constructs a new Queue.
|
|
21
25
|
* @param guildId The guild ID.
|
|
@@ -34,7 +38,7 @@ class MemoryQueue extends Array {
|
|
|
34
38
|
* @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
|
|
35
39
|
* @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
|
|
36
40
|
*/
|
|
37
|
-
|
|
41
|
+
add(track, offset) {
|
|
38
42
|
try {
|
|
39
43
|
const isArray = Array.isArray(track);
|
|
40
44
|
const tracks = isArray ? [...track] : [track];
|
|
@@ -122,15 +126,16 @@ class MemoryQueue extends Array {
|
|
|
122
126
|
* Adds a track to the previous tracks.
|
|
123
127
|
* @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
|
|
124
128
|
*/
|
|
125
|
-
|
|
129
|
+
addPrevious(track) {
|
|
126
130
|
try {
|
|
127
131
|
const max = this.manager.options.maxPreviousTracks;
|
|
132
|
+
this.previous = this.previous.filter((p) => p !== null);
|
|
128
133
|
if (Array.isArray(track)) {
|
|
129
|
-
const newTracks = track.filter((t) => !this.previous.some((p) => p
|
|
134
|
+
const newTracks = track.filter((t) => !this.previous.some((p) => p?.identifier === t.identifier));
|
|
130
135
|
this.previous.push(...newTracks);
|
|
131
136
|
}
|
|
132
137
|
else {
|
|
133
|
-
const exists = this.previous.some((p) => p
|
|
138
|
+
const exists = this.previous.some((p) => p?.identifier === track.identifier);
|
|
134
139
|
if (!exists) {
|
|
135
140
|
this.previous.push(track);
|
|
136
141
|
}
|
|
@@ -154,7 +159,7 @@ class MemoryQueue extends Array {
|
|
|
154
159
|
* Clears the queue.
|
|
155
160
|
* This will remove all tracks from the queue and emit a state update event.
|
|
156
161
|
*/
|
|
157
|
-
|
|
162
|
+
clear() {
|
|
158
163
|
try {
|
|
159
164
|
// Capture the current state of the player for event emission.
|
|
160
165
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
@@ -186,20 +191,32 @@ class MemoryQueue extends Array {
|
|
|
186
191
|
/**
|
|
187
192
|
* Clears the previous tracks.
|
|
188
193
|
*/
|
|
189
|
-
|
|
194
|
+
clearPrevious() {
|
|
190
195
|
this.previous = [];
|
|
191
196
|
}
|
|
192
197
|
/**
|
|
193
198
|
* Removes the first element from the queue.
|
|
194
199
|
*/
|
|
195
|
-
|
|
200
|
+
dequeue() {
|
|
196
201
|
return super.shift();
|
|
197
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Destroys the queue and releases all resources.
|
|
205
|
+
* After calling this method, the queue must not be used again.
|
|
206
|
+
*/
|
|
207
|
+
destroy() {
|
|
208
|
+
if (this.destroyed)
|
|
209
|
+
return;
|
|
210
|
+
this.destroyed = true;
|
|
211
|
+
this.splice(0);
|
|
212
|
+
this.previous.length = 0;
|
|
213
|
+
this.current = null;
|
|
214
|
+
}
|
|
198
215
|
/**
|
|
199
216
|
* The total duration of the queue in milliseconds.
|
|
200
217
|
* This includes the duration of the currently playing track.
|
|
201
218
|
*/
|
|
202
|
-
|
|
219
|
+
duration() {
|
|
203
220
|
const current = this.current?.duration ?? 0;
|
|
204
221
|
return this.reduce((acc, cur) => acc + (cur.duration || 0), current);
|
|
205
222
|
}
|
|
@@ -207,7 +224,7 @@ class MemoryQueue extends Array {
|
|
|
207
224
|
* Adds the specified track or tracks to the front of the queue.
|
|
208
225
|
* @param track The track or tracks to add.
|
|
209
226
|
*/
|
|
210
|
-
|
|
227
|
+
enqueueFront(track) {
|
|
211
228
|
if (Array.isArray(track)) {
|
|
212
229
|
this.unshift(...track);
|
|
213
230
|
}
|
|
@@ -218,49 +235,52 @@ class MemoryQueue extends Array {
|
|
|
218
235
|
/**
|
|
219
236
|
* @returns Whether all elements in the queue satisfy the provided testing function.
|
|
220
237
|
*/
|
|
221
|
-
|
|
238
|
+
everyAsync(callback) {
|
|
222
239
|
return this.every(callback);
|
|
223
240
|
}
|
|
224
241
|
/**
|
|
225
242
|
* @returns A new array with all elements that pass the test implemented by the provided function.
|
|
226
243
|
*/
|
|
227
|
-
|
|
244
|
+
filterAsync(callback) {
|
|
228
245
|
return this.filter(callback);
|
|
229
246
|
}
|
|
230
247
|
/**
|
|
231
248
|
* @returns The first element in the queue that satisfies the provided testing function.
|
|
232
249
|
*/
|
|
233
|
-
|
|
250
|
+
findAsync(callback) {
|
|
234
251
|
return this.find(callback);
|
|
235
252
|
}
|
|
236
253
|
/**
|
|
237
254
|
* @returns The current track.
|
|
238
255
|
*/
|
|
239
|
-
|
|
256
|
+
getCurrent() {
|
|
257
|
+
this.current = Utils_1.TrackUtils.revive(this.current);
|
|
240
258
|
return this.current;
|
|
241
259
|
}
|
|
242
260
|
/**
|
|
243
261
|
* @returns The previous tracks.
|
|
244
262
|
*/
|
|
245
|
-
|
|
263
|
+
getPrevious() {
|
|
264
|
+
this.previous = this.previous.map((t) => Utils_1.TrackUtils.revive(t));
|
|
246
265
|
return [...this.previous];
|
|
247
266
|
}
|
|
248
267
|
/**
|
|
249
268
|
* @returns The tracks in the queue from start to end.
|
|
250
269
|
*/
|
|
251
|
-
|
|
270
|
+
getSlice(start, end) {
|
|
252
271
|
return this.slice(start, end); // Native sync method, still wrapped in a Promise
|
|
253
272
|
}
|
|
254
273
|
/**
|
|
255
274
|
* @returns The tracks in the queue.
|
|
256
275
|
*/
|
|
257
|
-
|
|
276
|
+
getTracks() {
|
|
277
|
+
this.forEach((t) => Utils_1.TrackUtils.revive(t));
|
|
258
278
|
return [...this]; // clone to avoid direct mutation
|
|
259
279
|
}
|
|
260
280
|
/**
|
|
261
281
|
* @returns A new array with the results of calling a provided function on every element in the queue.
|
|
262
282
|
*/
|
|
263
|
-
|
|
283
|
+
mapAsync(callback) {
|
|
264
284
|
return this.map(callback);
|
|
265
285
|
}
|
|
266
286
|
/**
|
|
@@ -270,16 +290,16 @@ class MemoryQueue extends Array {
|
|
|
270
290
|
* @param items The elements to add to the queue.
|
|
271
291
|
* @returns The modified queue.
|
|
272
292
|
*/
|
|
273
|
-
|
|
293
|
+
modifyAt(start, deleteCount = 0, ...items) {
|
|
274
294
|
return super.splice(start, deleteCount, ...items);
|
|
275
295
|
}
|
|
276
296
|
/**
|
|
277
297
|
* @returns The newest track.
|
|
278
298
|
*/
|
|
279
|
-
|
|
299
|
+
popPrevious() {
|
|
280
300
|
return this.previous.pop() || null; // get newest track
|
|
281
301
|
}
|
|
282
|
-
|
|
302
|
+
remove(startOrPosition = 0, end) {
|
|
283
303
|
try {
|
|
284
304
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
285
305
|
if (typeof end !== "undefined") {
|
|
@@ -331,7 +351,7 @@ class MemoryQueue extends Array {
|
|
|
331
351
|
/**
|
|
332
352
|
* Shuffles the queue to play tracks requested by each user one by one.
|
|
333
353
|
*/
|
|
334
|
-
|
|
354
|
+
roundRobinShuffle() {
|
|
335
355
|
try {
|
|
336
356
|
// Capture the current state of the player for event emission.
|
|
337
357
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
@@ -339,11 +359,11 @@ class MemoryQueue extends Array {
|
|
|
339
359
|
const userTracks = new Map();
|
|
340
360
|
// Group the tracks in the queue by the user that requested them.
|
|
341
361
|
this.forEach((track) => {
|
|
342
|
-
const
|
|
343
|
-
if (!userTracks.has(
|
|
344
|
-
userTracks.set(
|
|
362
|
+
const userId = track.requester.id.toString();
|
|
363
|
+
if (!userTracks.has(userId)) {
|
|
364
|
+
userTracks.set(userId, []);
|
|
345
365
|
}
|
|
346
|
-
userTracks.get(
|
|
366
|
+
userTracks.get(userId).push(track);
|
|
347
367
|
});
|
|
348
368
|
// Shuffle the tracks of each user.
|
|
349
369
|
userTracks.forEach((tracks) => {
|
|
@@ -394,20 +414,20 @@ class MemoryQueue extends Array {
|
|
|
394
414
|
/**
|
|
395
415
|
* @param track The track to set.
|
|
396
416
|
*/
|
|
397
|
-
|
|
417
|
+
setCurrent(track) {
|
|
398
418
|
this.current = track;
|
|
399
419
|
}
|
|
400
420
|
/**
|
|
401
421
|
* @param tracks The tracks to set.
|
|
402
422
|
*/
|
|
403
|
-
|
|
423
|
+
setPrevious(tracks) {
|
|
404
424
|
this.previous = [...tracks];
|
|
405
425
|
}
|
|
406
426
|
/**
|
|
407
427
|
* Shuffles the queue.
|
|
408
428
|
* This will randomize the order of the tracks in the queue and emit a state update event.
|
|
409
429
|
*/
|
|
410
|
-
|
|
430
|
+
shuffle() {
|
|
411
431
|
try {
|
|
412
432
|
// Capture the current state of the player for event emission.
|
|
413
433
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
@@ -443,13 +463,13 @@ class MemoryQueue extends Array {
|
|
|
443
463
|
* This does not include the currently playing track.
|
|
444
464
|
* @returns The size of tracks in the queue.
|
|
445
465
|
*/
|
|
446
|
-
|
|
466
|
+
size() {
|
|
447
467
|
return this.length;
|
|
448
468
|
}
|
|
449
469
|
/**
|
|
450
470
|
* @returns Whether at least one element in the queue satisfies the provided testing function.
|
|
451
471
|
*/
|
|
452
|
-
|
|
472
|
+
someAsync(callback) {
|
|
453
473
|
return this.some(callback);
|
|
454
474
|
}
|
|
455
475
|
/**
|
|
@@ -457,24 +477,24 @@ class MemoryQueue extends Array {
|
|
|
457
477
|
* This includes the current track if it is not null.
|
|
458
478
|
* @returns The total size of tracks in the queue including the current track.
|
|
459
479
|
*/
|
|
460
|
-
|
|
480
|
+
totalSize() {
|
|
461
481
|
return this.length + (this.current ? 1 : 0);
|
|
462
482
|
}
|
|
463
483
|
/**
|
|
464
484
|
* Shuffles the queue to play tracks requested by each user one block at a time.
|
|
465
485
|
*/
|
|
466
|
-
|
|
486
|
+
userBlockShuffle() {
|
|
467
487
|
try {
|
|
468
488
|
// Capture the current state of the player for event emission.
|
|
469
489
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
470
490
|
// Group the tracks in the queue by the user that requested them.
|
|
471
491
|
const userTracks = new Map();
|
|
472
492
|
this.forEach((track) => {
|
|
473
|
-
const
|
|
474
|
-
if (!userTracks.has(
|
|
475
|
-
userTracks.set(
|
|
493
|
+
const userId = track.requester.id.toString();
|
|
494
|
+
if (!userTracks.has(userId)) {
|
|
495
|
+
userTracks.set(userId, []);
|
|
476
496
|
}
|
|
477
|
-
userTracks.get(
|
|
497
|
+
userTracks.get(userId).push(track);
|
|
478
498
|
});
|
|
479
499
|
// Create a new array for the shuffled queue.
|
|
480
500
|
const shuffledQueue = [];
|