magmastream 2.9.2-dev.6 → 2.9.2-dev.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.
- package/dist/index.d.ts +8 -2
- package/dist/statestorage/JsonQueue.js +102 -54
- package/dist/statestorage/MemoryQueue.js +63 -35
- package/dist/statestorage/RedisQueue.js +192 -107
- package/dist/structures/Utils.js +15 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1159,7 +1159,7 @@ interface Track {
|
|
|
1159
1159
|
/** The base64 encoded track. */
|
|
1160
1160
|
readonly track: string;
|
|
1161
1161
|
/** The artwork url of the track. */
|
|
1162
|
-
readonly artworkUrl: string;
|
|
1162
|
+
readonly artworkUrl: string | null;
|
|
1163
1163
|
/** The track source name. */
|
|
1164
1164
|
readonly sourceName: TrackSourceName;
|
|
1165
1165
|
/** The title of the track. */
|
|
@@ -1183,7 +1183,7 @@ interface Track {
|
|
|
1183
1183
|
/** The user that requested the track. */
|
|
1184
1184
|
requester?: AnyUser;
|
|
1185
1185
|
/** Displays the track thumbnail with optional size or null if it's a unsupported source. */
|
|
1186
|
-
displayThumbnail(size?: Sizes): string;
|
|
1186
|
+
displayThumbnail(size?: Sizes): string | null;
|
|
1187
1187
|
/** Additional track info provided by plugins. */
|
|
1188
1188
|
pluginInfo: TrackPluginInfo;
|
|
1189
1189
|
/** Add your own data to the track. */
|
|
@@ -3477,6 +3477,12 @@ declare abstract class TrackUtils {
|
|
|
3477
3477
|
* @returns Whether the search result is valid.
|
|
3478
3478
|
*/
|
|
3479
3479
|
static isErrorOrEmptySearchResult(result: SearchResult): result is ErrorOrEmptySearchResult;
|
|
3480
|
+
/**
|
|
3481
|
+
* Revives a track.
|
|
3482
|
+
* @param track The track to revive.
|
|
3483
|
+
* @returns The revived track.
|
|
3484
|
+
*/
|
|
3485
|
+
static revive(track: Track): Track;
|
|
3480
3486
|
}
|
|
3481
3487
|
declare abstract class AutoPlayUtils {
|
|
3482
3488
|
private static manager;
|
|
@@ -80,10 +80,14 @@ class JsonQueue {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
84
|
+
? err
|
|
85
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
86
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
87
|
+
message: `Failed to add tracks to JSON queue for guild ${this.guildId}: ${err.message}`,
|
|
88
|
+
cause: err,
|
|
89
|
+
});
|
|
90
|
+
console.error(error);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
/**
|
|
@@ -104,10 +108,14 @@ class JsonQueue {
|
|
|
104
108
|
await this.writeJSON(this.previousPath, trimmed);
|
|
105
109
|
}
|
|
106
110
|
catch (err) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
112
|
+
? err
|
|
113
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
114
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
115
|
+
message: `Failed to add tracks to JSON queue for guild ${this.guildId}: ${err.message}`,
|
|
116
|
+
cause: err,
|
|
117
|
+
});
|
|
118
|
+
console.error(error);
|
|
111
119
|
}
|
|
112
120
|
}
|
|
113
121
|
/**
|
|
@@ -128,10 +136,14 @@ class JsonQueue {
|
|
|
128
136
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Cleared the queue for: ${this.guildId}`);
|
|
129
137
|
}
|
|
130
138
|
catch (err) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
140
|
+
? err
|
|
141
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
142
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
143
|
+
message: `Failed to clear JSON queue for guild ${this.guildId}: ${err.message}`,
|
|
144
|
+
cause: err,
|
|
145
|
+
});
|
|
146
|
+
console.error(error);
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
/**
|
|
@@ -151,10 +163,14 @@ class JsonQueue {
|
|
|
151
163
|
return track;
|
|
152
164
|
}
|
|
153
165
|
catch (err) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
167
|
+
? err
|
|
168
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
169
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
170
|
+
message: `Failed to dequeue track for guild ${this.guildId}: ${err.message}`,
|
|
171
|
+
cause: err,
|
|
172
|
+
});
|
|
173
|
+
console.error(error);
|
|
158
174
|
}
|
|
159
175
|
}
|
|
160
176
|
/**
|
|
@@ -169,10 +185,14 @@ class JsonQueue {
|
|
|
169
185
|
return total;
|
|
170
186
|
}
|
|
171
187
|
catch (err) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
188
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
189
|
+
? err
|
|
190
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
191
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
192
|
+
message: `Failed to get duration for guild ${this.guildId}: ${err.message}`,
|
|
193
|
+
cause: err,
|
|
194
|
+
});
|
|
195
|
+
console.error(error);
|
|
176
196
|
}
|
|
177
197
|
}
|
|
178
198
|
/**
|
|
@@ -185,10 +205,14 @@ class JsonQueue {
|
|
|
185
205
|
await this.setQueue([...tracks.reverse(), ...queue]);
|
|
186
206
|
}
|
|
187
207
|
catch (err) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
208
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
209
|
+
? err
|
|
210
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
211
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
212
|
+
message: `Failed to enqueue front track for guild ${this.guildId}: ${err.message}`,
|
|
213
|
+
cause: err,
|
|
214
|
+
});
|
|
215
|
+
console.error(error);
|
|
192
216
|
}
|
|
193
217
|
}
|
|
194
218
|
/**
|
|
@@ -216,14 +240,15 @@ class JsonQueue {
|
|
|
216
240
|
* @returns The current track.
|
|
217
241
|
*/
|
|
218
242
|
async getCurrent() {
|
|
219
|
-
|
|
243
|
+
const track = await this.readJSON(this.currentPath);
|
|
244
|
+
return track ? Utils_1.TrackUtils.revive(track) : null;
|
|
220
245
|
}
|
|
221
246
|
/**
|
|
222
247
|
* @returns The previous tracks.
|
|
223
248
|
*/
|
|
224
249
|
async getPrevious() {
|
|
225
250
|
const data = await this.readJSON(this.previousPath);
|
|
226
|
-
return Array.isArray(data) ? data : [];
|
|
251
|
+
return Array.isArray(data) ? data.map(Utils_1.TrackUtils.revive) : [];
|
|
227
252
|
}
|
|
228
253
|
/**
|
|
229
254
|
* @returns The tracks in the queue from start to end.
|
|
@@ -269,10 +294,14 @@ class JsonQueue {
|
|
|
269
294
|
return popped;
|
|
270
295
|
}
|
|
271
296
|
catch (err) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
297
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
298
|
+
? err
|
|
299
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
300
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
301
|
+
message: `Failed to pop previous track for guild ${this.guildId}: ${err.message}`,
|
|
302
|
+
cause: err,
|
|
303
|
+
});
|
|
304
|
+
console.error(error);
|
|
276
305
|
}
|
|
277
306
|
}
|
|
278
307
|
async remove(startOrPos = 0, end) {
|
|
@@ -301,10 +330,14 @@ class JsonQueue {
|
|
|
301
330
|
return removed;
|
|
302
331
|
}
|
|
303
332
|
catch (err) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
333
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
334
|
+
? err
|
|
335
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
336
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
337
|
+
message: `Failed to remove track for guild ${this.guildId}: ${err.message}`,
|
|
338
|
+
cause: err,
|
|
339
|
+
});
|
|
340
|
+
console.error(error);
|
|
308
341
|
}
|
|
309
342
|
}
|
|
310
343
|
/**
|
|
@@ -349,10 +382,14 @@ class JsonQueue {
|
|
|
349
382
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
|
|
350
383
|
}
|
|
351
384
|
catch (err) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
385
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
386
|
+
? err
|
|
387
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
388
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
389
|
+
message: `Failed to round robin shuffle queue for guild ${this.guildId}: ${err.message}`,
|
|
390
|
+
cause: err,
|
|
391
|
+
});
|
|
392
|
+
console.error(error);
|
|
356
393
|
}
|
|
357
394
|
}
|
|
358
395
|
/**
|
|
@@ -397,10 +434,14 @@ class JsonQueue {
|
|
|
397
434
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Shuffled the queue for: ${this.guildId}`);
|
|
398
435
|
}
|
|
399
436
|
catch (err) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
437
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
438
|
+
? err
|
|
439
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
440
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
441
|
+
message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
|
|
442
|
+
cause: err,
|
|
443
|
+
});
|
|
444
|
+
console.error(error);
|
|
404
445
|
}
|
|
405
446
|
}
|
|
406
447
|
/**
|
|
@@ -457,10 +498,14 @@ class JsonQueue {
|
|
|
457
498
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
|
|
458
499
|
}
|
|
459
500
|
catch (err) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
501
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
502
|
+
? err
|
|
503
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
504
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
505
|
+
message: `Failed to user block shuffle queue for guild ${this.guildId}: ${err.message}`,
|
|
506
|
+
cause: err,
|
|
507
|
+
});
|
|
508
|
+
console.error(error);
|
|
464
509
|
}
|
|
465
510
|
}
|
|
466
511
|
// #endregion Public
|
|
@@ -478,12 +523,16 @@ class JsonQueue {
|
|
|
478
523
|
try {
|
|
479
524
|
await fs_1.promises.unlink(filePath);
|
|
480
525
|
}
|
|
481
|
-
catch {
|
|
526
|
+
catch (err) {
|
|
527
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
528
|
+
? err
|
|
529
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
530
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
531
|
+
message: `Failed to delete file: ${filePath}`,
|
|
532
|
+
cause: err,
|
|
533
|
+
});
|
|
534
|
+
console.error(error);
|
|
482
535
|
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Failed to delete file: ${filePath}`);
|
|
483
|
-
throw new MagmastreamError_1.MagmaStreamError({
|
|
484
|
-
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
485
|
-
message: `Failed to delete file: ${filePath}`,
|
|
486
|
-
});
|
|
487
536
|
}
|
|
488
537
|
}
|
|
489
538
|
/**
|
|
@@ -497,7 +546,7 @@ class JsonQueue {
|
|
|
497
546
|
*/
|
|
498
547
|
async getQueue() {
|
|
499
548
|
const data = await this.readJSON(this.queuePath);
|
|
500
|
-
return Array.isArray(data) ? data : [];
|
|
549
|
+
return Array.isArray(data) ? data.map(Utils_1.TrackUtils.revive) : [];
|
|
501
550
|
}
|
|
502
551
|
/**
|
|
503
552
|
* @returns The previous path.
|
|
@@ -525,9 +574,8 @@ class JsonQueue {
|
|
|
525
574
|
? err
|
|
526
575
|
: new MagmastreamError_1.MagmaStreamError({
|
|
527
576
|
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
528
|
-
message:
|
|
577
|
+
message: `Failed to read file: ${filePath}`,
|
|
529
578
|
cause: err,
|
|
530
|
-
context: { stage: "SIGINT" },
|
|
531
579
|
});
|
|
532
580
|
console.error(error);
|
|
533
581
|
return null;
|
|
@@ -41,7 +41,7 @@ class MemoryQueue extends Array {
|
|
|
41
41
|
// Get the track info as a string
|
|
42
42
|
const trackInfo = isArray ? tracks.map((t) => Utils_1.JSONUtils.safe(t, 2)).join(", ") : Utils_1.JSONUtils.safe(track, 2);
|
|
43
43
|
// Emit a debug message
|
|
44
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
44
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Added ${tracks.length} track(s) to queue: ${trackInfo}`);
|
|
45
45
|
const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
|
|
46
46
|
// If the queue is empty, set the track as the current track
|
|
47
47
|
if (!this.current) {
|
|
@@ -109,10 +109,14 @@ class MemoryQueue extends Array {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
catch (err) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
113
|
+
? err
|
|
114
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
115
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
116
|
+
message: `Failed to add tracks to queue for guild ${this.guildId}: ${err.message}`,
|
|
117
|
+
cause: err,
|
|
118
|
+
});
|
|
119
|
+
console.error(error);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
/**
|
|
@@ -137,10 +141,14 @@ class MemoryQueue extends Array {
|
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
143
|
catch (err) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
145
|
+
? err
|
|
146
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
147
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
148
|
+
message: `Failed to add tracks to previous tracks for guild ${this.guildId}: ${err.message}`,
|
|
149
|
+
cause: err,
|
|
150
|
+
});
|
|
151
|
+
console.error(error);
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
/**
|
|
@@ -163,13 +171,17 @@ class MemoryQueue extends Array {
|
|
|
163
171
|
},
|
|
164
172
|
});
|
|
165
173
|
// Emit a debug message indicating the queue has been cleared for a specific guild ID.
|
|
166
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
174
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Cleared the queue for: ${this.guildId}`);
|
|
167
175
|
}
|
|
168
176
|
catch (err) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
178
|
+
? err
|
|
179
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
180
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
181
|
+
message: `Failed to clear queue for guild ${this.guildId}: ${err.message}`,
|
|
182
|
+
cause: err,
|
|
183
|
+
});
|
|
184
|
+
console.error(error);
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
187
|
/**
|
|
@@ -280,7 +292,7 @@ class MemoryQueue extends Array {
|
|
|
280
292
|
throw new RangeError("Invalid range: start should be less than end and within queue length.");
|
|
281
293
|
}
|
|
282
294
|
const removedTracks = this.splice(startOrPosition, end - startOrPosition);
|
|
283
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
295
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Removed ${removedTracks.length} track(s) from player: ${this.guildId} from position ${startOrPosition} to ${end}.`);
|
|
284
296
|
this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
|
|
285
297
|
changeType: Enums_1.PlayerStateEventTypes.QueueChange,
|
|
286
298
|
details: {
|
|
@@ -293,7 +305,7 @@ class MemoryQueue extends Array {
|
|
|
293
305
|
}
|
|
294
306
|
// Single item removal when no end specified
|
|
295
307
|
const removedTrack = this.splice(startOrPosition, 1);
|
|
296
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
308
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Removed 1 track from player: ${this.guildId} from position ${startOrPosition}: ${Utils_1.JSONUtils.safe(removedTrack[0], 2)}`);
|
|
297
309
|
// Ensure removedTrack is an array for consistency
|
|
298
310
|
const tracksToEmit = removedTrack.length > 0 ? removedTrack : [];
|
|
299
311
|
this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
|
|
@@ -307,10 +319,14 @@ class MemoryQueue extends Array {
|
|
|
307
319
|
return removedTrack;
|
|
308
320
|
}
|
|
309
321
|
catch (err) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
322
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
323
|
+
? err
|
|
324
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
325
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
326
|
+
message: `Failed to remove track(s) from queue for guild ${this.guildId}: ${err.message}`,
|
|
327
|
+
cause: err,
|
|
328
|
+
});
|
|
329
|
+
console.error(error);
|
|
314
330
|
}
|
|
315
331
|
}
|
|
316
332
|
/**
|
|
@@ -363,13 +379,17 @@ class MemoryQueue extends Array {
|
|
|
363
379
|
},
|
|
364
380
|
});
|
|
365
381
|
// Emit a debug message indicating the queue has been shuffled for a specific guild ID.
|
|
366
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
382
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
|
|
367
383
|
}
|
|
368
384
|
catch (err) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
385
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
386
|
+
? err
|
|
387
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
388
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
389
|
+
message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
|
|
390
|
+
cause: err,
|
|
391
|
+
});
|
|
392
|
+
console.error(error);
|
|
373
393
|
}
|
|
374
394
|
}
|
|
375
395
|
/**
|
|
@@ -406,13 +426,17 @@ class MemoryQueue extends Array {
|
|
|
406
426
|
},
|
|
407
427
|
});
|
|
408
428
|
// Emit a debug message indicating the queue has been shuffled for a specific guild ID.
|
|
409
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
429
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Shuffled the queue for: ${this.guildId}`);
|
|
410
430
|
}
|
|
411
431
|
catch (err) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
432
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
433
|
+
? err
|
|
434
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
435
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
436
|
+
message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
|
|
437
|
+
cause: err,
|
|
438
|
+
});
|
|
439
|
+
console.error(error);
|
|
416
440
|
}
|
|
417
441
|
}
|
|
418
442
|
/**
|
|
@@ -477,13 +501,17 @@ class MemoryQueue extends Array {
|
|
|
477
501
|
},
|
|
478
502
|
});
|
|
479
503
|
// Emit a debug message indicating the queue has been shuffled for a specific guild ID.
|
|
480
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
504
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
|
|
481
505
|
}
|
|
482
506
|
catch (err) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
507
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
508
|
+
? err
|
|
509
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
510
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
|
|
511
|
+
message: `Failed to add tracks to queue for guild ${this.guildId}: ${err.message}`,
|
|
512
|
+
cause: err,
|
|
513
|
+
});
|
|
514
|
+
console.error(error);
|
|
487
515
|
}
|
|
488
516
|
}
|
|
489
517
|
}
|
|
@@ -68,12 +68,16 @@ class RedisQueue {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
catch (err) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
72
|
+
? err
|
|
73
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
74
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
75
|
+
message: `Failed to add tracks to Redis queue for guild ${this.guildId}: ${err.message}`,
|
|
76
|
+
cause: err,
|
|
77
|
+
});
|
|
78
|
+
console.error(error);
|
|
75
79
|
}
|
|
76
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
80
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Added ${tracks.length} track(s) to queue`);
|
|
77
81
|
// Autoplay logic
|
|
78
82
|
if (this.manager.players.has(this.guildId) && this.manager.players.get(this.guildId).isAutoplay) {
|
|
79
83
|
if (!Array.isArray(track)) {
|
|
@@ -101,12 +105,14 @@ class RedisQueue {
|
|
|
101
105
|
});
|
|
102
106
|
}
|
|
103
107
|
catch (err) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
109
|
+
? err
|
|
110
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
111
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
112
|
+
message: `Unexpected error in add() for guild ${this.guildId}: ${err.message}`,
|
|
113
|
+
cause: err,
|
|
114
|
+
});
|
|
115
|
+
console.error(error);
|
|
110
116
|
}
|
|
111
117
|
}
|
|
112
118
|
/**
|
|
@@ -131,19 +137,25 @@ class RedisQueue {
|
|
|
131
137
|
await this.redis.ltrim(this.previousKey, -max, -1);
|
|
132
138
|
}
|
|
133
139
|
catch (err) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
141
|
+
? err
|
|
142
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
143
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
144
|
+
message: `Failed to add previous tracks to Redis for guild ${this.guildId}: ${err.message}`,
|
|
145
|
+
cause: err,
|
|
146
|
+
});
|
|
147
|
+
console.error(error);
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
catch (err) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
152
|
+
? err
|
|
153
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
154
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
155
|
+
message: `Unexpected error in addPrevious() for guild ${this.guildId}: ${err.message}`,
|
|
156
|
+
cause: err,
|
|
157
|
+
});
|
|
158
|
+
console.error(error);
|
|
147
159
|
}
|
|
148
160
|
}
|
|
149
161
|
/**
|
|
@@ -155,10 +167,14 @@ class RedisQueue {
|
|
|
155
167
|
await this.redis.del(this.queueKey);
|
|
156
168
|
}
|
|
157
169
|
catch (err) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
171
|
+
? err
|
|
172
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
173
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
174
|
+
message: `Failed to clear queue for guild ${this.guildId}: ${err.message}`,
|
|
175
|
+
cause: err,
|
|
176
|
+
});
|
|
177
|
+
console.error(error);
|
|
162
178
|
}
|
|
163
179
|
this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
|
|
164
180
|
changeType: Enums_1.PlayerStateEventTypes.QueueChange,
|
|
@@ -168,7 +184,7 @@ class RedisQueue {
|
|
|
168
184
|
tracks: [],
|
|
169
185
|
},
|
|
170
186
|
});
|
|
171
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
187
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Cleared the queue for: ${this.guildId}`);
|
|
172
188
|
}
|
|
173
189
|
/**
|
|
174
190
|
* Clears the previous tracks.
|
|
@@ -178,10 +194,14 @@ class RedisQueue {
|
|
|
178
194
|
await this.redis.del(this.previousKey);
|
|
179
195
|
}
|
|
180
196
|
catch (err) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
197
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
198
|
+
? err
|
|
199
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
200
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
201
|
+
message: `Failed to clear previous tracks for guild ${this.guildId}: ${err.message}`,
|
|
202
|
+
cause: err,
|
|
203
|
+
});
|
|
204
|
+
console.error(error);
|
|
185
205
|
}
|
|
186
206
|
}
|
|
187
207
|
/**
|
|
@@ -193,10 +213,14 @@ class RedisQueue {
|
|
|
193
213
|
return raw ? this.deserialize(raw) : undefined;
|
|
194
214
|
}
|
|
195
215
|
catch (err) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
216
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
217
|
+
? err
|
|
218
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
219
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
220
|
+
message: `Failed to dequeue track for guild ${this.guildId}: ${err.message}`,
|
|
221
|
+
cause: err,
|
|
222
|
+
});
|
|
223
|
+
console.error(error);
|
|
200
224
|
}
|
|
201
225
|
}
|
|
202
226
|
/**
|
|
@@ -214,17 +238,21 @@ class RedisQueue {
|
|
|
214
238
|
}
|
|
215
239
|
catch (err) {
|
|
216
240
|
// Skip invalid tracks but log
|
|
217
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
241
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Skipping invalid track during duration calculation for guild ${this.guildId}: ${err.message}`);
|
|
218
242
|
return acc;
|
|
219
243
|
}
|
|
220
244
|
}, currentDuration);
|
|
221
245
|
return total;
|
|
222
246
|
}
|
|
223
247
|
catch (err) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
248
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
249
|
+
? err
|
|
250
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
251
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
252
|
+
message: `Failed to calculate total queue duration for guild ${this.guildId}: ${err.message}`,
|
|
253
|
+
cause: err,
|
|
254
|
+
});
|
|
255
|
+
console.error(error);
|
|
228
256
|
}
|
|
229
257
|
}
|
|
230
258
|
/**
|
|
@@ -238,10 +266,14 @@ class RedisQueue {
|
|
|
238
266
|
await this.redis.lpush(this.queueKey, ...serialized.reverse());
|
|
239
267
|
}
|
|
240
268
|
catch (err) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
269
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
270
|
+
? err
|
|
271
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
272
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
273
|
+
message: `Failed to enqueue track to front for guild ${this.guildId}: ${err.message}`,
|
|
274
|
+
cause: err,
|
|
275
|
+
});
|
|
276
|
+
console.error(error);
|
|
245
277
|
}
|
|
246
278
|
}
|
|
247
279
|
/**
|
|
@@ -280,10 +312,14 @@ class RedisQueue {
|
|
|
280
312
|
return raw ? this.deserialize(raw) : null;
|
|
281
313
|
}
|
|
282
314
|
catch (err) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
315
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
316
|
+
? err
|
|
317
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
318
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
319
|
+
message: `Failed to get current track for guild ${this.guildId}: ${err.message}`,
|
|
320
|
+
cause: err,
|
|
321
|
+
});
|
|
322
|
+
console.error(error);
|
|
287
323
|
}
|
|
288
324
|
}
|
|
289
325
|
/**
|
|
@@ -295,10 +331,14 @@ class RedisQueue {
|
|
|
295
331
|
return raw.map(this.deserialize);
|
|
296
332
|
}
|
|
297
333
|
catch (err) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
334
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
335
|
+
? err
|
|
336
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
337
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
338
|
+
message: `Failed to get previous tracks for guild ${this.guildId}: ${err.message}`,
|
|
339
|
+
cause: err,
|
|
340
|
+
});
|
|
341
|
+
console.error(error);
|
|
302
342
|
}
|
|
303
343
|
}
|
|
304
344
|
/**
|
|
@@ -310,10 +350,14 @@ class RedisQueue {
|
|
|
310
350
|
return raw.map(this.deserialize);
|
|
311
351
|
}
|
|
312
352
|
catch (err) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
353
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
354
|
+
? err
|
|
355
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
356
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
357
|
+
message: `Failed to get slice of queue for guild ${this.guildId}: ${err.message}`,
|
|
358
|
+
cause: err,
|
|
359
|
+
});
|
|
360
|
+
console.error(error);
|
|
317
361
|
}
|
|
318
362
|
}
|
|
319
363
|
/**
|
|
@@ -325,10 +369,14 @@ class RedisQueue {
|
|
|
325
369
|
return raw.map(this.deserialize);
|
|
326
370
|
}
|
|
327
371
|
catch (err) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
372
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
373
|
+
? err
|
|
374
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
375
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
376
|
+
message: `Failed to get tracks for guild ${this.guildId}: ${err.message}`,
|
|
377
|
+
cause: err,
|
|
378
|
+
});
|
|
379
|
+
console.error(error);
|
|
332
380
|
}
|
|
333
381
|
}
|
|
334
382
|
/**
|
|
@@ -357,10 +405,14 @@ class RedisQueue {
|
|
|
357
405
|
return removed.map(this.deserialize);
|
|
358
406
|
}
|
|
359
407
|
catch (err) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
408
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
409
|
+
? err
|
|
410
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
411
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
412
|
+
message: `Failed to modify queue at index ${start} for guild ${this.guildId}: ${err.message}`,
|
|
413
|
+
cause: err,
|
|
414
|
+
});
|
|
415
|
+
console.error(error);
|
|
364
416
|
}
|
|
365
417
|
}
|
|
366
418
|
/**
|
|
@@ -374,10 +426,14 @@ class RedisQueue {
|
|
|
374
426
|
return raw ? this.deserialize(raw) : null;
|
|
375
427
|
}
|
|
376
428
|
catch (err) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
429
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
430
|
+
? err
|
|
431
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
432
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
433
|
+
message: `Failed to pop previous track for guild ${this.guildId}: ${err.message}`,
|
|
434
|
+
cause: err,
|
|
435
|
+
});
|
|
436
|
+
console.error(error);
|
|
381
437
|
}
|
|
382
438
|
}
|
|
383
439
|
async remove(startOrPos = 0, end) {
|
|
@@ -400,7 +456,7 @@ class RedisQueue {
|
|
|
400
456
|
await this.redis.rpush(this.queueKey, ...queue);
|
|
401
457
|
}
|
|
402
458
|
const deserialized = removed.map(this.deserialize);
|
|
403
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
459
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Removed ${removed.length} track(s) from position ${startOrPos}${end ? ` to ${end}` : ""}`);
|
|
404
460
|
this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
|
|
405
461
|
changeType: Enums_1.PlayerStateEventTypes.QueueChange,
|
|
406
462
|
details: {
|
|
@@ -411,11 +467,15 @@ class RedisQueue {
|
|
|
411
467
|
});
|
|
412
468
|
return deserialized;
|
|
413
469
|
}
|
|
414
|
-
catch (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
470
|
+
catch (err) {
|
|
471
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
472
|
+
? err
|
|
473
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
474
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
475
|
+
message: `Failed to remove track for guild ${this.guildId}: ${err.message}`,
|
|
476
|
+
cause: err,
|
|
477
|
+
});
|
|
478
|
+
console.error(error);
|
|
419
479
|
}
|
|
420
480
|
}
|
|
421
481
|
/**
|
|
@@ -459,13 +519,17 @@ class RedisQueue {
|
|
|
459
519
|
action: "roundRobin",
|
|
460
520
|
},
|
|
461
521
|
});
|
|
462
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
522
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
|
|
463
523
|
}
|
|
464
|
-
catch (
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
524
|
+
catch (err) {
|
|
525
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
526
|
+
? err
|
|
527
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
528
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
529
|
+
message: `Failed to roundRobinShuffle the queue for guild ${this.guildId}: ${err.message}`,
|
|
530
|
+
cause: err,
|
|
531
|
+
});
|
|
532
|
+
console.error(error);
|
|
469
533
|
}
|
|
470
534
|
}
|
|
471
535
|
/**
|
|
@@ -481,11 +545,15 @@ class RedisQueue {
|
|
|
481
545
|
await this.redis.del(this.currentKey);
|
|
482
546
|
}
|
|
483
547
|
}
|
|
484
|
-
catch (
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
548
|
+
catch (err) {
|
|
549
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
550
|
+
? err
|
|
551
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
552
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
553
|
+
message: `Failed to setCurrent the queue for guild ${this.guildId}: ${err.message}`,
|
|
554
|
+
cause: err,
|
|
555
|
+
});
|
|
556
|
+
console.error(error);
|
|
489
557
|
}
|
|
490
558
|
}
|
|
491
559
|
/**
|
|
@@ -503,11 +571,15 @@ class RedisQueue {
|
|
|
503
571
|
.rpush(this.previousKey, ...tracks.map(this.serialize))
|
|
504
572
|
.exec();
|
|
505
573
|
}
|
|
506
|
-
catch (
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
574
|
+
catch (err) {
|
|
575
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
576
|
+
? err
|
|
577
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
578
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
579
|
+
message: `Failed to setPrevious the queue for guild ${this.guildId}: ${err.message}`,
|
|
580
|
+
cause: err,
|
|
581
|
+
});
|
|
582
|
+
console.error(error);
|
|
511
583
|
}
|
|
512
584
|
}
|
|
513
585
|
/**
|
|
@@ -532,13 +604,17 @@ class RedisQueue {
|
|
|
532
604
|
action: "shuffle",
|
|
533
605
|
},
|
|
534
606
|
});
|
|
535
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
607
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Shuffled the queue for: ${this.guildId}`);
|
|
536
608
|
}
|
|
537
|
-
catch (
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
609
|
+
catch (err) {
|
|
610
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
611
|
+
? err
|
|
612
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
613
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
614
|
+
message: `Failed to shuffle the queue for guild ${this.guildId}: ${err.message}`,
|
|
615
|
+
cause: err,
|
|
616
|
+
});
|
|
617
|
+
console.error(error);
|
|
542
618
|
}
|
|
543
619
|
}
|
|
544
620
|
/**
|
|
@@ -548,11 +624,15 @@ class RedisQueue {
|
|
|
548
624
|
try {
|
|
549
625
|
return await this.redis.llen(this.queueKey);
|
|
550
626
|
}
|
|
551
|
-
catch (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
627
|
+
catch (err) {
|
|
628
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
629
|
+
? err
|
|
630
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
631
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
632
|
+
message: `Failed to get the size of the queue for guild ${this.guildId}: ${err.message}`,
|
|
633
|
+
cause: err,
|
|
634
|
+
});
|
|
635
|
+
console.error(error);
|
|
556
636
|
}
|
|
557
637
|
}
|
|
558
638
|
/**
|
|
@@ -601,13 +681,17 @@ class RedisQueue {
|
|
|
601
681
|
action: "userBlock",
|
|
602
682
|
},
|
|
603
683
|
});
|
|
604
|
-
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[
|
|
684
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
|
|
605
685
|
}
|
|
606
|
-
catch (
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
686
|
+
catch (err) {
|
|
687
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
688
|
+
? err
|
|
689
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
690
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
|
|
691
|
+
message: `Failed to userBlockShuffle the queue for guild ${this.guildId}: ${err.message}`,
|
|
692
|
+
cause: err,
|
|
693
|
+
});
|
|
694
|
+
console.error(error);
|
|
611
695
|
}
|
|
612
696
|
}
|
|
613
697
|
// #endregion Public
|
|
@@ -622,7 +706,8 @@ class RedisQueue {
|
|
|
622
706
|
* Deserializes a track from a string.
|
|
623
707
|
*/
|
|
624
708
|
deserialize(data) {
|
|
625
|
-
|
|
709
|
+
const track = JSON.parse(data);
|
|
710
|
+
return Utils_1.TrackUtils.revive(track);
|
|
626
711
|
}
|
|
627
712
|
/**
|
|
628
713
|
* @returns The previous key.
|
package/dist/structures/Utils.js
CHANGED
|
@@ -128,7 +128,7 @@ class TrackUtils {
|
|
|
128
128
|
isSeekable: data.info.isSeekable,
|
|
129
129
|
isStream: data.info.isStream,
|
|
130
130
|
uri: data.info.uri,
|
|
131
|
-
artworkUrl: data.info?.artworkUrl,
|
|
131
|
+
artworkUrl: data.info?.artworkUrl ?? null,
|
|
132
132
|
sourceName: sourceNameMap[data.info?.sourceName?.toLowerCase() ?? ""] ?? data.info?.sourceName,
|
|
133
133
|
thumbnail: data.info.uri.includes("youtube") ? `https://img.youtube.com/vi/${data.info.identifier}/default.jpg` : null,
|
|
134
134
|
displayThumbnail(size = "default") {
|
|
@@ -168,6 +168,20 @@ class TrackUtils {
|
|
|
168
168
|
static isErrorOrEmptySearchResult(result) {
|
|
169
169
|
return result.loadType === Enums_1.LoadTypes.Empty || result.loadType === Enums_1.LoadTypes.Error;
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Revives a track.
|
|
173
|
+
* @param track The track to revive.
|
|
174
|
+
* @returns The revived track.
|
|
175
|
+
*/
|
|
176
|
+
static revive(track) {
|
|
177
|
+
if (!track)
|
|
178
|
+
return track;
|
|
179
|
+
track.displayThumbnail = function (size = "default") {
|
|
180
|
+
const finalSize = SIZES.find((s) => s === size) ?? "default";
|
|
181
|
+
return this.uri.includes("youtube") ? `https://img.youtube.com/vi/${this.identifier}/${finalSize}.jpg` : null;
|
|
182
|
+
}.bind(track);
|
|
183
|
+
return track;
|
|
184
|
+
}
|
|
171
185
|
}
|
|
172
186
|
exports.TrackUtils = TrackUtils;
|
|
173
187
|
class AutoPlayUtils {
|