magmastream 2.9.3-dev.25 → 2.9.3-dev.26

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.
@@ -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
+ }
@@ -102,8 +102,11 @@ class JsonQueue {
102
102
  const tracks = Array.isArray(track) ? track : [track];
103
103
  if (!tracks.length)
104
104
  return;
105
- const current = await this.getPrevious();
106
- const newTracks = tracks.filter((t) => !current.some((p) => p.uri === t.uri));
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));
107
110
  if (!newTracks.length)
108
111
  return;
109
112
  const updated = [...current, ...newTracks];
@@ -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
+ }
@@ -129,12 +129,13 @@ class MemoryQueue extends Array {
129
129
  addPrevious(track) {
130
130
  try {
131
131
  const max = this.manager.options.maxPreviousTracks;
132
+ this.previous = this.previous.filter((p) => p !== null);
132
133
  if (Array.isArray(track)) {
133
- const newTracks = track.filter((t) => !this.previous.some((p) => p.identifier === t.identifier));
134
+ const newTracks = track.filter((t) => !this.previous.some((p) => p?.identifier === t.identifier));
134
135
  this.previous.push(...newTracks);
135
136
  }
136
137
  else {
137
- const exists = this.previous.some((p) => p.identifier === track.identifier);
138
+ const exists = this.previous.some((p) => p?.identifier === track.identifier);
138
139
  if (!exists) {
139
140
  this.previous.push(track);
140
141
  }
@@ -253,12 +254,14 @@ class MemoryQueue extends Array {
253
254
  * @returns The current track.
254
255
  */
255
256
  getCurrent() {
257
+ this.current = Utils_1.TrackUtils.revive(this.current);
256
258
  return this.current;
257
259
  }
258
260
  /**
259
261
  * @returns The previous tracks.
260
262
  */
261
263
  getPrevious() {
264
+ this.previous = this.previous.map((t) => Utils_1.TrackUtils.revive(t));
262
265
  return [...this.previous];
263
266
  }
264
267
  /**
@@ -271,6 +274,7 @@ class MemoryQueue extends Array {
271
274
  * @returns The tracks in the queue.
272
275
  */
273
276
  getTracks() {
277
+ this.forEach((t) => Utils_1.TrackUtils.revive(t));
274
278
  return [...this]; // clone to avoid direct mutation
275
279
  }
276
280
  /**
@@ -0,0 +1,178 @@
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 RedisQueue implements IQueue {
7
+ readonly guildId: string;
8
+ readonly manager: Manager;
9
+ /**
10
+ * The prefix for the Redis keys.
11
+ */
12
+ redisPrefix: string;
13
+ /**
14
+ * The Redis instance.
15
+ */
16
+ private redis;
17
+ /**
18
+ * Whether the queue has been destroyed.
19
+ */
20
+ private destroyed;
21
+ /**
22
+ * Constructs a new RedisQueue.
23
+ * @param guildId The guild ID.
24
+ * @param manager The Manager instance.
25
+ */
26
+ constructor(guildId: string, manager: Manager);
27
+ /**
28
+ * Adds a track or tracks to the queue.
29
+ * @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
30
+ * @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.
31
+ */
32
+ add(track: Track | Track[], offset?: number): Promise<void>;
33
+ /**
34
+ * Adds a track or tracks to the previous tracks.
35
+ * @param track The track or tracks to add.
36
+ */
37
+ addPrevious(track: Track | Track[]): Promise<void>;
38
+ /**
39
+ * Clears the queue.
40
+ */
41
+ clear(): Promise<void>;
42
+ /**
43
+ * Clears the previous tracks.
44
+ */
45
+ clearPrevious(): Promise<void>;
46
+ /**
47
+ * Removes the first track from the queue.
48
+ */
49
+ dequeue(): Promise<Track | undefined>;
50
+ /**
51
+ * Destroys the queue and releases all resources.
52
+ * After calling this method, the queue must not be used again.
53
+ */
54
+ destroy(): Promise<void>;
55
+ /**
56
+ * @returns The total duration of the queue in milliseconds.
57
+ * This includes the duration of the currently playing track.
58
+ */
59
+ duration(): Promise<number>;
60
+ /**
61
+ * Adds a track to the front of the queue.
62
+ * @param track The track or tracks to add.
63
+ */
64
+ enqueueFront(track: Track | Track[]): Promise<void>;
65
+ /**
66
+ * Whether all tracks in the queue match the specified condition.
67
+ * @param callback The condition to match.
68
+ * @returns Whether all tracks in the queue match the specified condition.
69
+ */
70
+ everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
71
+ /**
72
+ * Filters the tracks in the queue.
73
+ * @param callback The condition to match.
74
+ * @returns The tracks that match the condition.
75
+ */
76
+ filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
77
+ /**
78
+ * Finds the first track in the queue that matches the specified condition.
79
+ * @param callback The condition to match.
80
+ * @returns The first track that matches the condition.
81
+ */
82
+ findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
83
+ /**
84
+ * @returns The current track.
85
+ */
86
+ getCurrent(): Promise<Track | null>;
87
+ /**
88
+ * @returns The previous tracks.
89
+ */
90
+ getPrevious(): Promise<Track[]>;
91
+ /**
92
+ * @returns The tracks in the queue from the start to the end.
93
+ */
94
+ getSlice(start?: number, end?: number): Promise<Track[]>;
95
+ /**
96
+ * @returns The tracks in the queue.
97
+ */
98
+ getTracks(): Promise<Track[]>;
99
+ /**
100
+ * Maps the tracks in the queue.
101
+ * @returns The tracks in the queue after the specified index.
102
+ */
103
+ mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
104
+ /**
105
+ * Modifies the queue at the specified index.
106
+ * @param start The start index.
107
+ * @param deleteCount The number of tracks to delete.
108
+ * @param items The tracks to insert.
109
+ * @returns The removed tracks.
110
+ */
111
+ modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
112
+ /**
113
+ * Removes the newest track.
114
+ * @returns The newest track.
115
+ */
116
+ popPrevious(): Promise<Track | null>;
117
+ /**
118
+ * Removes the track at the specified index.
119
+ * @param position The position to remove the track at.
120
+ * @param end The end position to remove the track at.
121
+ */
122
+ remove(position?: number): Promise<Track[]>;
123
+ remove(start: number, end: number): Promise<Track[]>;
124
+ /**
125
+ * Shuffles the queue round-robin style.
126
+ */
127
+ roundRobinShuffle(): Promise<void>;
128
+ /**
129
+ * Sets the current track.
130
+ * @param track The track to set.
131
+ */
132
+ setCurrent(track: Track | null): Promise<void>;
133
+ /**
134
+ * Sets the previous track(s).
135
+ * @param track The track to set.
136
+ */
137
+ setPrevious(track: Track | Track[]): Promise<void>;
138
+ /**
139
+ * Shuffles the queue.
140
+ */
141
+ shuffle(): Promise<void>;
142
+ /**
143
+ * @returns The size of the queue.
144
+ */
145
+ size(): Promise<number>;
146
+ /**
147
+ * @returns Whether any tracks in the queue match the specified condition.
148
+ */
149
+ someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
150
+ /**
151
+ * @returns The total size of tracks in the queue including the current track.
152
+ */
153
+ totalSize(): Promise<number>;
154
+ /**
155
+ * Shuffles the queue, but keeps the tracks of the same user together.
156
+ */
157
+ userBlockShuffle(): Promise<void>;
158
+ /**
159
+ * @returns The current key.
160
+ */
161
+ private get currentKey();
162
+ /**
163
+ * Deserializes a track from a string.
164
+ */
165
+ private deserialize;
166
+ /**
167
+ * @returns The previous key.
168
+ */
169
+ private get previousKey();
170
+ /**
171
+ * @returns The queue key.
172
+ */
173
+ private get queueKey();
174
+ /**
175
+ * Helper to serialize/deserialize Track
176
+ */
177
+ private serialize;
178
+ }