magmastream 2.9.2-dev.6 → 2.9.2-dev.7

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 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. */
@@ -80,10 +80,14 @@ class JsonQueue {
80
80
  });
81
81
  }
82
82
  catch (err) {
83
- throw new MagmastreamError_1.MagmaStreamError({
84
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
85
- message: `Failed to add tracks to JSON queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
108
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
109
- message: `Failed to add tracks to JSON queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
132
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
133
- message: `Failed to clear JSON queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
155
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
156
- message: `Failed to dequeue track for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
173
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
174
- message: `Failed to get duration for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
189
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
190
- message: `Failed to enqueue front track for guild ${this.guildId}: ${err.message}`,
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
  /**
@@ -269,10 +293,14 @@ class JsonQueue {
269
293
  return popped;
270
294
  }
271
295
  catch (err) {
272
- throw new MagmastreamError_1.MagmaStreamError({
273
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
274
- message: `Failed to pop previous track for guild ${this.guildId}: ${err.message}`,
275
- });
296
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
297
+ ? err
298
+ : new MagmastreamError_1.MagmaStreamError({
299
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
300
+ message: `Failed to pop previous track for guild ${this.guildId}: ${err.message}`,
301
+ cause: err,
302
+ });
303
+ console.error(error);
276
304
  }
277
305
  }
278
306
  async remove(startOrPos = 0, end) {
@@ -301,10 +329,14 @@ class JsonQueue {
301
329
  return removed;
302
330
  }
303
331
  catch (err) {
304
- throw new MagmastreamError_1.MagmaStreamError({
305
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
306
- message: `Failed to remove track for guild ${this.guildId}: ${err.message}`,
307
- });
332
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
333
+ ? err
334
+ : new MagmastreamError_1.MagmaStreamError({
335
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
336
+ message: `Failed to remove track for guild ${this.guildId}: ${err.message}`,
337
+ cause: err,
338
+ });
339
+ console.error(error);
308
340
  }
309
341
  }
310
342
  /**
@@ -349,10 +381,14 @@ class JsonQueue {
349
381
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
350
382
  }
351
383
  catch (err) {
352
- throw new MagmastreamError_1.MagmaStreamError({
353
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
354
- message: `Failed to round robin shuffle queue for guild ${this.guildId}: ${err.message}`,
355
- });
384
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
385
+ ? err
386
+ : new MagmastreamError_1.MagmaStreamError({
387
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
388
+ message: `Failed to round robin shuffle queue for guild ${this.guildId}: ${err.message}`,
389
+ cause: err,
390
+ });
391
+ console.error(error);
356
392
  }
357
393
  }
358
394
  /**
@@ -397,10 +433,14 @@ class JsonQueue {
397
433
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Shuffled the queue for: ${this.guildId}`);
398
434
  }
399
435
  catch (err) {
400
- throw new MagmastreamError_1.MagmaStreamError({
401
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
402
- message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
403
- });
436
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
437
+ ? err
438
+ : new MagmastreamError_1.MagmaStreamError({
439
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
440
+ message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
441
+ cause: err,
442
+ });
443
+ console.error(error);
404
444
  }
405
445
  }
406
446
  /**
@@ -457,10 +497,14 @@ class JsonQueue {
457
497
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
458
498
  }
459
499
  catch (err) {
460
- throw new MagmastreamError_1.MagmaStreamError({
461
- code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
462
- message: `Failed to user block shuffle queue for guild ${this.guildId}: ${err.message}`,
463
- });
500
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
501
+ ? err
502
+ : new MagmastreamError_1.MagmaStreamError({
503
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
504
+ message: `Failed to user block shuffle queue for guild ${this.guildId}: ${err.message}`,
505
+ cause: err,
506
+ });
507
+ console.error(error);
464
508
  }
465
509
  }
466
510
  // #endregion Public
@@ -478,12 +522,16 @@ class JsonQueue {
478
522
  try {
479
523
  await fs_1.promises.unlink(filePath);
480
524
  }
481
- catch {
525
+ catch (err) {
526
+ const error = err instanceof MagmastreamError_1.MagmaStreamError
527
+ ? err
528
+ : new MagmastreamError_1.MagmaStreamError({
529
+ code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
530
+ message: `Failed to delete file: ${filePath}`,
531
+ cause: err,
532
+ });
533
+ console.error(error);
482
534
  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
535
  }
488
536
  }
489
537
  /**
@@ -525,9 +573,8 @@ class JsonQueue {
525
573
  ? err
526
574
  : new MagmastreamError_1.MagmaStreamError({
527
575
  code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
528
- message: "An unknown error occurred.",
576
+ message: `Failed to read file: ${filePath}`,
529
577
  cause: err,
530
- context: { stage: "SIGINT" },
531
578
  });
532
579
  console.error(error);
533
580
  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, `[QUEUE] Added ${tracks.length} track(s) to queue: ${trackInfo}`);
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
- throw new MagmastreamError_1.MagmaStreamError({
113
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
114
- message: `Failed to add tracks to queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
141
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
142
- message: `Failed to add tracks to previous tracks for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Cleared the queue for: ${this.guildId}`);
174
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Cleared the queue for: ${this.guildId}`);
167
175
  }
168
176
  catch (err) {
169
- throw new MagmastreamError_1.MagmaStreamError({
170
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
171
- message: `Failed to clear queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Removed ${removedTracks.length} track(s) from player: ${this.guildId} from position ${startOrPosition} to ${end}.`);
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, `[QUEUE] Removed 1 track from player: ${this.guildId} from position ${startOrPosition}: ${Utils_1.JSONUtils.safe(removedTrack[0], 2)}`);
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
- throw new MagmastreamError_1.MagmaStreamError({
311
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
312
- message: `Failed to remove track(s) from queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
382
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
367
383
  }
368
384
  catch (err) {
369
- throw new MagmastreamError_1.MagmaStreamError({
370
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
371
- message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Shuffled the queue for: ${this.guildId}`);
429
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] Shuffled the queue for: ${this.guildId}`);
410
430
  }
411
431
  catch (err) {
412
- throw new MagmastreamError_1.MagmaStreamError({
413
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
414
- message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] userBlockShuffled the queue for: ${this.guildId}`);
504
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[MEMORYQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
481
505
  }
482
506
  catch (err) {
483
- throw new MagmastreamError_1.MagmaStreamError({
484
- code: Enums_1.MagmaStreamErrorCode.QUEUE_MEMORY_ERROR,
485
- message: `Failed to shuffle queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
72
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
73
- message: `Failed to add tracks to Redis queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Added ${tracks.length} track(s) to queue`);
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
- if (err instanceof MagmastreamError_1.MagmaStreamError)
105
- throw err;
106
- throw new MagmastreamError_1.MagmaStreamError({
107
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
108
- message: `Unexpected error in add() for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
135
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
136
- message: `Failed to add previous tracks to Redis for guild ${this.guildId}: ${err.message}`,
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
- if (err instanceof MagmastreamError_1.MagmaStreamError)
142
- throw err;
143
- throw new MagmastreamError_1.MagmaStreamError({
144
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
145
- message: `Unexpected error in addPrevious() for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
159
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
160
- message: `Failed to clear queue for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Cleared the queue for: ${this.guildId}`);
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
- throw new MagmastreamError_1.MagmaStreamError({
182
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
183
- message: `Failed to clear previous tracks for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
197
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
198
- message: `Failed to dequeue track for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Skipping invalid track during duration calculation for guild ${this.guildId}: ${err.message}`);
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
- throw new MagmastreamError_1.MagmaStreamError({
225
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
226
- message: `Failed to calculate total queue duration for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
242
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
243
- message: `Failed to enqueue track to front for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
284
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
285
- message: `Failed to get current track for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
299
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
300
- message: `Failed to get previous tracks for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
314
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
315
- message: `Failed to get slice of queue for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
329
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
330
- message: `Failed to get tracks for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
361
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
362
- message: `Failed to modify queue at index ${start} for guild ${this.guildId}: ${err.message}`,
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
- throw new MagmastreamError_1.MagmaStreamError({
378
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
379
- message: `Failed to pop previous track for guild ${this.guildId}: ${err.message}`,
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, `[QUEUE] Removed ${removed.length} track(s) from position ${startOrPos}${end ? ` to ${end}` : ""}`);
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 (error) {
415
- throw new MagmastreamError_1.MagmaStreamError({
416
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
417
- message: `Failed to remove track for guild ${this.guildId}: ${error.message}`,
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, `[QUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
522
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
463
523
  }
464
- catch (error) {
465
- throw new MagmastreamError_1.MagmaStreamError({
466
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
467
- message: `Failed to roundRobinShuffle the queue for guild ${this.guildId}: ${error.message}`,
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 (error) {
485
- throw new MagmastreamError_1.MagmaStreamError({
486
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
487
- message: `Failed to setCurrent the queue for guild ${this.guildId}: ${error.message}`,
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 (error) {
507
- throw new MagmastreamError_1.MagmaStreamError({
508
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
509
- message: `Failed to setPrevious the queue for guild ${this.guildId}: ${error.message}`,
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, `[QUEUE] Shuffled the queue for: ${this.guildId}`);
607
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] Shuffled the queue for: ${this.guildId}`);
536
608
  }
537
- catch (error) {
538
- throw new MagmastreamError_1.MagmaStreamError({
539
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
540
- message: `Failed to shuffle the queue for guild ${this.guildId}: ${error.message}`,
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 (error) {
552
- throw new MagmastreamError_1.MagmaStreamError({
553
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
554
- message: `Failed to get the size of the queue for guild ${this.guildId}: ${error.message}`,
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, `[QUEUE] userBlockShuffled the queue for: ${this.guildId}`);
684
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REDISQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
605
685
  }
606
- catch (error) {
607
- throw new MagmastreamError_1.MagmaStreamError({
608
- code: Enums_1.MagmaStreamErrorCode.QUEUE_REDIS_ERROR,
609
- message: `Failed to userBlockShuffle the queue for guild ${this.guildId}: ${error.message}`,
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
@@ -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") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.9.2-dev.6",
3
+ "version": "2.9.2-dev.7",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",