magmastream 2.0.1-beta → 2.0.2-beta
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 +23 -66
- package/dist/structures/Filters.js +61 -90
- package/dist/structures/Manager.js +4 -10
- package/dist/structures/Node.js +24 -65
- package/dist/structures/Queue.js +30 -33
- package/dist/structures/Rest.js +26 -62
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Collection } from '@discordjs/collection';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import WebSocket from 'ws';
|
|
5
|
-
import { Pool
|
|
5
|
+
import { Pool } from 'undici';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
|
|
@@ -28,7 +28,7 @@ declare class Queue extends Array<Track | UnresolvedTrack> {
|
|
|
28
28
|
* Removes a track from the queue. Defaults to the first track, returning the removed track, EXCLUDING THE `current` TRACK.
|
|
29
29
|
* @param [position=0]
|
|
30
30
|
*/
|
|
31
|
-
remove(position?: number): Track[];
|
|
31
|
+
remove(position?: number): (Track | UnresolvedTrack)[];
|
|
32
32
|
/**
|
|
33
33
|
* Removes an amount of tracks using a exclusive start and end exclusive index, returning the removed tracks, EXCLUDING THE `current` TRACK.
|
|
34
34
|
* @param start
|
|
@@ -51,72 +51,43 @@ declare class Filters {
|
|
|
51
51
|
karaoke: karaokeOptions;
|
|
52
52
|
distortion: distortionOptions;
|
|
53
53
|
constructor(player: Player);
|
|
54
|
+
private updateFilters;
|
|
55
|
+
private applyFilter;
|
|
54
56
|
/**
|
|
55
57
|
* Sets the equalizer bands and updates the filters.
|
|
56
58
|
* @param bands - The equalizer bands.
|
|
57
59
|
*/
|
|
58
60
|
setEqualizer(bands?: Band[]): this;
|
|
59
|
-
/**
|
|
60
|
-
* Applies the 8D filter.
|
|
61
|
-
*/
|
|
61
|
+
/** Applies the eight dimension audio effect. */
|
|
62
62
|
eightD(): this;
|
|
63
|
-
/**
|
|
64
|
-
* Applies the bass boost filter.
|
|
65
|
-
*/
|
|
63
|
+
/** Applies the bass boost effect. */
|
|
66
64
|
bassBoost(): this;
|
|
67
|
-
/**
|
|
68
|
-
* Applies the nightcore filter.
|
|
69
|
-
*/
|
|
65
|
+
/** Applies the nightcore effect. */
|
|
70
66
|
nightcore(): this;
|
|
71
|
-
/**
|
|
72
|
-
* Applies the slow motion filter.
|
|
73
|
-
*/
|
|
67
|
+
/** Applies the slow motion audio effect. */
|
|
74
68
|
slowmo(): this;
|
|
75
|
-
/**
|
|
76
|
-
* Applies the soft filter.
|
|
77
|
-
*/
|
|
69
|
+
/** Applies the soft audio effect. */
|
|
78
70
|
soft(): this;
|
|
79
|
-
/**
|
|
80
|
-
* Applies the TV filter.
|
|
81
|
-
*/
|
|
71
|
+
/** Applies the television audio effect. */
|
|
82
72
|
tv(): this;
|
|
83
|
-
/**
|
|
84
|
-
* Applies the treble bass filter.
|
|
85
|
-
*/
|
|
73
|
+
/** Applies the treble bass effect. */
|
|
86
74
|
trebleBass(): this;
|
|
87
|
-
/**
|
|
88
|
-
* Applies the vaporwave filter.
|
|
89
|
-
*/
|
|
75
|
+
/** Applies the vaporwave effect. */
|
|
90
76
|
vaporwave(): this;
|
|
91
|
-
/**
|
|
92
|
-
* Applies the distortion filter.
|
|
93
|
-
*/
|
|
77
|
+
/** Applies the distortion audio effect. */
|
|
94
78
|
distort(): this;
|
|
95
|
-
/**
|
|
96
|
-
* Applies the karaoke options specified by the filter.
|
|
97
|
-
*/
|
|
79
|
+
/** Applies the karaoke options specified by the filter. */
|
|
98
80
|
setKaraoke(karaoke?: karaokeOptions): this;
|
|
99
|
-
/**
|
|
100
|
-
* Applies the timescale options specified by the filter.
|
|
101
|
-
*/
|
|
81
|
+
/** Applies the timescale options specified by the filter. */
|
|
102
82
|
setTimescale(timescale?: timescaleOptions): this;
|
|
103
|
-
/**
|
|
104
|
-
* Applies the vibrato options specified by the filter.
|
|
105
|
-
*/
|
|
83
|
+
/** Applies the vibrato options specified by the filter. */
|
|
106
84
|
setVibrato(vibrato?: vibratoOptions): this;
|
|
107
|
-
/**
|
|
108
|
-
* Applies the rotation options specified by the filter.
|
|
109
|
-
*/
|
|
85
|
+
/** Applies the rotation options specified by the filter. */
|
|
110
86
|
setRotation(rotation?: rotationOptions): this;
|
|
87
|
+
/** Applies the distortion options specified by the filter. */
|
|
111
88
|
setDistortion(distortion?: distortionOptions): this;
|
|
112
|
-
/**
|
|
113
|
-
* Clears the filters.
|
|
114
|
-
*/
|
|
89
|
+
/** Removes the audio effects. */
|
|
115
90
|
clearFilters(): this;
|
|
116
|
-
/**
|
|
117
|
-
* Updates the filters.
|
|
118
|
-
*/
|
|
119
|
-
updateFilters(): this;
|
|
120
91
|
}
|
|
121
92
|
/** Options for adjusting the timescale of audio. */
|
|
122
93
|
interface timescaleOptions {
|
|
@@ -553,7 +524,7 @@ interface NowPlayingMessage {
|
|
|
553
524
|
/** The delete function. */
|
|
554
525
|
delete: () => Promise<void>;
|
|
555
526
|
/** The edit function. */
|
|
556
|
-
edit: () => void
|
|
527
|
+
edit: () => Promise<void>;
|
|
557
528
|
}
|
|
558
529
|
|
|
559
530
|
/** Handles the requests sent to the Lavalink REST API. */
|
|
@@ -576,7 +547,8 @@ declare class Rest {
|
|
|
576
547
|
updatePlayer(options: playOptions): Promise<unknown>;
|
|
577
548
|
/** Sends a DELETE request to the server to destroy the player. */
|
|
578
549
|
destroyPlayer(guildId: string): Promise<unknown>;
|
|
579
|
-
|
|
550
|
+
private request;
|
|
551
|
+
get(endpoint: RouteLike): Promise<unknown>;
|
|
580
552
|
patch(endpoint: RouteLike, body: unknown): Promise<unknown>;
|
|
581
553
|
post(endpoint: RouteLike, body: unknown): Promise<unknown>;
|
|
582
554
|
delete(endpoint: RouteLike): Promise<unknown>;
|
|
@@ -641,19 +613,6 @@ declare class Node {
|
|
|
641
613
|
connect(): void;
|
|
642
614
|
/** Destroys the Node and all players connected with it. */
|
|
643
615
|
destroy(): void;
|
|
644
|
-
/**
|
|
645
|
-
* Makes an API call to the Node
|
|
646
|
-
* @param endpoint The endpoint that we will make the call to
|
|
647
|
-
* @param modify Used to modify the request before being sent
|
|
648
|
-
* @returns The returned data
|
|
649
|
-
*/
|
|
650
|
-
makeRequest<T>(endpoint: string, modify?: ModifyRequest): Promise<T>;
|
|
651
|
-
/**
|
|
652
|
-
* Sends data to the Node.
|
|
653
|
-
* @param data
|
|
654
|
-
* @deprecated
|
|
655
|
-
*/
|
|
656
|
-
send(data: unknown): Promise<boolean>;
|
|
657
616
|
private reconnect;
|
|
658
617
|
protected open(): void;
|
|
659
618
|
protected close(code: number, reason: string): void;
|
|
@@ -667,8 +626,6 @@ declare class Node {
|
|
|
667
626
|
protected trackError(player: Player, track: Track | UnresolvedTrack, payload: TrackExceptionEvent): void;
|
|
668
627
|
protected socketClosed(player: Player, payload: WebSocketClosedEvent): void;
|
|
669
628
|
}
|
|
670
|
-
/** Modifies any outgoing REST requests. */
|
|
671
|
-
type ModifyRequest = (options: Dispatcher.RequestOptions) => void;
|
|
672
629
|
interface NodeOptions {
|
|
673
630
|
/** The host for the node. */
|
|
674
631
|
host: string;
|
|
@@ -970,4 +927,4 @@ interface PlaylistData {
|
|
|
970
927
|
tracks: Track[];
|
|
971
928
|
}
|
|
972
929
|
|
|
973
|
-
export { CPUStats, EqualizerBand, Exception, Extendable, FrameStats, LavalinkResponse, LoadType, Manager, ManagerOptions, MemoryStats,
|
|
930
|
+
export { CPUStats, EqualizerBand, Exception, Extendable, FrameStats, LavalinkResponse, LoadType, Manager, ManagerOptions, MemoryStats, Node, NodeMessage, NodeOptions, NodeStats, NowPlayingMessage, Payload, PlayOptions, Player, PlayerEvent, PlayerEventType, PlayerEvents, PlayerOptions, PlayerUpdate, PlaylistData, PlaylistRawData, Plugin, Queue, SearchPlatform, SearchQuery, SearchResult, Severity, Sizes, State, Structure, Track, TrackData, TrackDataInfo, TrackEndEvent, TrackEndReason, TrackExceptionEvent, TrackStartEvent, TrackStuckEvent, TrackUtils, UnresolvedQuery, UnresolvedTrack, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent };
|
|
@@ -3,40 +3,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Filters = void 0;
|
|
4
4
|
class Filters {
|
|
5
5
|
player;
|
|
6
|
-
volume
|
|
7
|
-
equalizer
|
|
8
|
-
vibrato
|
|
9
|
-
rotation
|
|
10
|
-
timescale
|
|
11
|
-
karaoke
|
|
12
|
-
distortion
|
|
6
|
+
volume;
|
|
7
|
+
equalizer;
|
|
8
|
+
vibrato;
|
|
9
|
+
rotation;
|
|
10
|
+
timescale;
|
|
11
|
+
karaoke;
|
|
12
|
+
distortion;
|
|
13
13
|
constructor(player) {
|
|
14
14
|
this.player = player;
|
|
15
|
+
this.volume = 1.0;
|
|
16
|
+
this.equalizer = [];
|
|
17
|
+
this.vibrato = null;
|
|
18
|
+
this.rotation = null;
|
|
19
|
+
this.timescale = null;
|
|
20
|
+
this.karaoke = null;
|
|
21
|
+
this.distortion = null;
|
|
22
|
+
}
|
|
23
|
+
updateFilters() {
|
|
24
|
+
const { equalizer, karaoke, timescale, vibrato, rotation, volume, distortion, } = this;
|
|
25
|
+
this.player.node.rest.updatePlayer({
|
|
26
|
+
guildId: this.player.guild,
|
|
27
|
+
data: {
|
|
28
|
+
filters: {
|
|
29
|
+
volume,
|
|
30
|
+
equalizer,
|
|
31
|
+
karaoke,
|
|
32
|
+
timescale,
|
|
33
|
+
vibrato,
|
|
34
|
+
rotation,
|
|
35
|
+
distortion,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
applyFilter(filter, updateFilters = true) {
|
|
42
|
+
this[filter.property] = filter.value;
|
|
43
|
+
if (updateFilters) {
|
|
44
|
+
this.updateFilters();
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
15
47
|
}
|
|
16
48
|
/**
|
|
17
49
|
* Sets the equalizer bands and updates the filters.
|
|
18
50
|
* @param bands - The equalizer bands.
|
|
19
51
|
*/
|
|
20
52
|
setEqualizer(bands) {
|
|
21
|
-
this.equalizer
|
|
22
|
-
this.updateFilters();
|
|
23
|
-
return this;
|
|
53
|
+
return this.applyFilter({ property: "equalizer", value: bands });
|
|
24
54
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Applies the 8D filter.
|
|
27
|
-
*/
|
|
55
|
+
/** Applies the eight dimension audio effect. */
|
|
28
56
|
eightD() {
|
|
29
57
|
return this.setRotation({ rotationHz: 0.2 });
|
|
30
58
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Applies the bass boost filter.
|
|
33
|
-
*/
|
|
59
|
+
/** Applies the bass boost effect. */
|
|
34
60
|
bassBoost() {
|
|
35
61
|
return this.setEqualizer(bassBoostEqualizer);
|
|
36
62
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Applies the nightcore filter.
|
|
39
|
-
*/
|
|
63
|
+
/** Applies the nightcore effect. */
|
|
40
64
|
nightcore() {
|
|
41
65
|
return this.setTimescale({
|
|
42
66
|
speed: 1.1,
|
|
@@ -44,9 +68,7 @@ class Filters {
|
|
|
44
68
|
rate: 1.05,
|
|
45
69
|
});
|
|
46
70
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Applies the slow motion filter.
|
|
49
|
-
*/
|
|
71
|
+
/** Applies the slow motion audio effect. */
|
|
50
72
|
slowmo() {
|
|
51
73
|
return this.setTimescale({
|
|
52
74
|
speed: 0.7,
|
|
@@ -54,34 +76,23 @@ class Filters {
|
|
|
54
76
|
rate: 0.8,
|
|
55
77
|
});
|
|
56
78
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Applies the soft filter.
|
|
59
|
-
*/
|
|
79
|
+
/** Applies the soft audio effect. */
|
|
60
80
|
soft() {
|
|
61
81
|
return this.setEqualizer(softEqualizer);
|
|
62
82
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Applies the TV filter.
|
|
65
|
-
*/
|
|
83
|
+
/** Applies the television audio effect. */
|
|
66
84
|
tv() {
|
|
67
85
|
return this.setEqualizer(tvEqualizer);
|
|
68
86
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Applies the treble bass filter.
|
|
71
|
-
*/
|
|
87
|
+
/** Applies the treble bass effect. */
|
|
72
88
|
trebleBass() {
|
|
73
89
|
return this.setEqualizer(trebleBassEqualizer);
|
|
74
90
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Applies the vaporwave filter.
|
|
77
|
-
*/
|
|
91
|
+
/** Applies the vaporwave effect. */
|
|
78
92
|
vaporwave() {
|
|
79
|
-
this.setEqualizer(vaporwaveEqualizer);
|
|
80
|
-
return this.setTimescale({ pitch: 0.55 });
|
|
93
|
+
return this.setEqualizer(vaporwaveEqualizer).setTimescale({ pitch: 0.55 });
|
|
81
94
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Applies the distortion filter.
|
|
84
|
-
*/
|
|
95
|
+
/** Applies the distortion audio effect. */
|
|
85
96
|
distort() {
|
|
86
97
|
return this.setDistortion({
|
|
87
98
|
sinOffset: 0,
|
|
@@ -94,72 +105,32 @@ class Filters {
|
|
|
94
105
|
scale: 1.2,
|
|
95
106
|
});
|
|
96
107
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Applies the karaoke options specified by the filter.
|
|
99
|
-
*/
|
|
108
|
+
/** Applies the karaoke options specified by the filter. */
|
|
100
109
|
setKaraoke(karaoke) {
|
|
101
|
-
this.karaoke
|
|
102
|
-
this.updateFilters();
|
|
103
|
-
return this;
|
|
110
|
+
return this.applyFilter({ property: "karaoke", value: karaoke });
|
|
104
111
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Applies the timescale options specified by the filter.
|
|
107
|
-
*/
|
|
112
|
+
/** Applies the timescale options specified by the filter. */
|
|
108
113
|
setTimescale(timescale) {
|
|
109
|
-
this.timescale
|
|
110
|
-
this.updateFilters();
|
|
111
|
-
return this;
|
|
114
|
+
return this.applyFilter({ property: "timescale", value: timescale });
|
|
112
115
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Applies the vibrato options specified by the filter.
|
|
115
|
-
*/
|
|
116
|
+
/** Applies the vibrato options specified by the filter. */
|
|
116
117
|
setVibrato(vibrato) {
|
|
117
|
-
this.vibrato
|
|
118
|
-
this.updateFilters();
|
|
119
|
-
return this;
|
|
118
|
+
return this.applyFilter({ property: "vibrato", value: vibrato });
|
|
120
119
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Applies the rotation options specified by the filter.
|
|
123
|
-
*/
|
|
120
|
+
/** Applies the rotation options specified by the filter. */
|
|
124
121
|
setRotation(rotation) {
|
|
125
|
-
this.rotation
|
|
126
|
-
this.updateFilters();
|
|
127
|
-
return this;
|
|
122
|
+
return this.applyFilter({ property: "rotation", value: rotation });
|
|
128
123
|
}
|
|
124
|
+
/** Applies the distortion options specified by the filter. */
|
|
129
125
|
setDistortion(distortion) {
|
|
130
|
-
this.distortion
|
|
131
|
-
this.updateFilters();
|
|
132
|
-
return this;
|
|
126
|
+
return this.applyFilter({ property: "distortion", value: distortion });
|
|
133
127
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Clears the filters.
|
|
136
|
-
*/
|
|
128
|
+
/** Removes the audio effects. */
|
|
137
129
|
clearFilters() {
|
|
138
130
|
this.player.filters = new Filters(this.player);
|
|
139
131
|
this.updateFilters();
|
|
140
132
|
return this;
|
|
141
133
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Updates the filters.
|
|
144
|
-
*/
|
|
145
|
-
updateFilters() {
|
|
146
|
-
const { equalizer, karaoke, timescale, vibrato, rotation, volume, distortion, } = this;
|
|
147
|
-
this.player.node.rest.updatePlayer({
|
|
148
|
-
guildId: this.player.guild,
|
|
149
|
-
data: {
|
|
150
|
-
filters: {
|
|
151
|
-
volume,
|
|
152
|
-
equalizer,
|
|
153
|
-
karaoke,
|
|
154
|
-
timescale,
|
|
155
|
-
vibrato,
|
|
156
|
-
rotation,
|
|
157
|
-
distortion,
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
134
|
}
|
|
164
135
|
exports.Filters = Filters;
|
|
165
136
|
const bassBoostEqualizer = [
|
|
@@ -167,8 +167,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
167
167
|
searchData = res.data;
|
|
168
168
|
break;
|
|
169
169
|
case "track":
|
|
170
|
-
|
|
171
|
-
searchData = [data];
|
|
170
|
+
searchData = [res.data];
|
|
172
171
|
break;
|
|
173
172
|
case "playlist":
|
|
174
173
|
playlistData = res.data;
|
|
@@ -196,14 +195,9 @@ class Manager extends events_1.EventEmitter {
|
|
|
196
195
|
const node = this.nodes.first();
|
|
197
196
|
if (!node)
|
|
198
197
|
throw new Error("No available nodes.");
|
|
199
|
-
const res = await node
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
r.body = JSON.stringify(tracks);
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
204
|
-
r.headers["Content-Type"] = "application/json";
|
|
205
|
-
})
|
|
206
|
-
.catch((err) => reject(err));
|
|
198
|
+
const res = (await node.rest
|
|
199
|
+
.post("/v4/decodetracks", JSON.stringify(tracks))
|
|
200
|
+
.catch((err) => reject(err)));
|
|
207
201
|
if (!res) {
|
|
208
202
|
return reject(new Error("No data returned from query."));
|
|
209
203
|
}
|
package/dist/structures/Node.js
CHANGED
|
@@ -148,49 +148,6 @@ class Node {
|
|
|
148
148
|
this.manager.emit("nodeDestroy", this);
|
|
149
149
|
this.manager.destroyNode(this.options.identifier);
|
|
150
150
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Makes an API call to the Node
|
|
153
|
-
* @param endpoint The endpoint that we will make the call to
|
|
154
|
-
* @param modify Used to modify the request before being sent
|
|
155
|
-
* @returns The returned data
|
|
156
|
-
*/
|
|
157
|
-
async makeRequest(endpoint, modify) {
|
|
158
|
-
const options = {
|
|
159
|
-
path: `/${endpoint.replace(/^\//gm, "")}`,
|
|
160
|
-
method: "GET",
|
|
161
|
-
headers: {
|
|
162
|
-
Authorization: this.options.password,
|
|
163
|
-
},
|
|
164
|
-
headersTimeout: this.options.requestTimeout,
|
|
165
|
-
};
|
|
166
|
-
modify?.(options);
|
|
167
|
-
const request = await this.http.request(options);
|
|
168
|
-
this.calls++;
|
|
169
|
-
return await request.body.json();
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Sends data to the Node.
|
|
173
|
-
* @param data
|
|
174
|
-
* @deprecated
|
|
175
|
-
*/
|
|
176
|
-
send(data) {
|
|
177
|
-
return new Promise((resolve, reject) => {
|
|
178
|
-
if (!this.connected)
|
|
179
|
-
return resolve(false);
|
|
180
|
-
if (!data)
|
|
181
|
-
return reject(false);
|
|
182
|
-
const payload = JSON.stringify(data);
|
|
183
|
-
if (!payload?.startsWith("{")) {
|
|
184
|
-
return reject(false);
|
|
185
|
-
}
|
|
186
|
-
this.socket.send(payload, (error) => {
|
|
187
|
-
if (error)
|
|
188
|
-
reject(error);
|
|
189
|
-
else
|
|
190
|
-
resolve(true);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
151
|
reconnect() {
|
|
195
152
|
this.reconnectTimeout = setTimeout(() => {
|
|
196
153
|
if (this.reconnectAttempts >= this.options.retryAmount) {
|
|
@@ -265,27 +222,29 @@ class Node {
|
|
|
265
222
|
return;
|
|
266
223
|
const track = player.queue.current;
|
|
267
224
|
const type = payload.type;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
player?.nowPlayingMessage?.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
225
|
+
switch (type) {
|
|
226
|
+
case "TrackStartEvent":
|
|
227
|
+
this.trackStart(player, track, payload);
|
|
228
|
+
break;
|
|
229
|
+
case "TrackEndEvent":
|
|
230
|
+
if (player?.nowPlayingMessage && !player?.nowPlayingMessage?.deleted) {
|
|
231
|
+
player?.nowPlayingMessage?.delete().catch(() => { });
|
|
232
|
+
}
|
|
233
|
+
this.trackEnd(player, track, payload);
|
|
234
|
+
break;
|
|
235
|
+
case "TrackStuckEvent":
|
|
236
|
+
this.trackStuck(player, track, payload);
|
|
237
|
+
break;
|
|
238
|
+
case "TrackExceptionEvent":
|
|
239
|
+
this.trackError(player, track, payload);
|
|
240
|
+
break;
|
|
241
|
+
case "WebSocketClosedEvent":
|
|
242
|
+
this.socketClosed(player, payload);
|
|
243
|
+
break;
|
|
244
|
+
default:
|
|
245
|
+
const error = new Error(`Node#event unknown event '${type}'.`);
|
|
246
|
+
this.manager.emit("nodeError", this, error);
|
|
247
|
+
break;
|
|
289
248
|
}
|
|
290
249
|
}
|
|
291
250
|
trackStart(player, track, payload) {
|
|
@@ -295,7 +254,7 @@ class Node {
|
|
|
295
254
|
}
|
|
296
255
|
trackEnd(player, track, payload) {
|
|
297
256
|
// If a track had an error while starting
|
|
298
|
-
if (["
|
|
257
|
+
if (["loadFailed", "cleanup"].includes(payload.reason)) {
|
|
299
258
|
player.queue.previous = player.queue.current;
|
|
300
259
|
player.queue.current = player.queue.shift();
|
|
301
260
|
if (!player.queue.current)
|
package/dist/structures/Queue.js
CHANGED
|
@@ -9,8 +9,7 @@ class Queue extends Array {
|
|
|
9
9
|
/** The total duration of the queue. */
|
|
10
10
|
get duration() {
|
|
11
11
|
const current = this.current?.duration ?? 0;
|
|
12
|
-
return this
|
|
13
|
-
.reduce((acc, cur) => acc + (cur.duration || 0), current);
|
|
12
|
+
return this.reduce((acc, cur) => acc + (cur.duration || 0), current);
|
|
14
13
|
}
|
|
15
14
|
/** The total size of tracks in the queue including the current track. */
|
|
16
15
|
get totalSize() {
|
|
@@ -34,48 +33,46 @@ class Queue extends Array {
|
|
|
34
33
|
throw new RangeError('Track must be a "Track" or "Track[]".');
|
|
35
34
|
}
|
|
36
35
|
if (!this.current) {
|
|
37
|
-
if (
|
|
38
|
-
this.current = track;
|
|
39
|
-
|
|
36
|
+
if (Array.isArray(track)) {
|
|
37
|
+
this.current = track.shift() || null;
|
|
38
|
+
this.push(...track);
|
|
40
39
|
}
|
|
41
40
|
else {
|
|
42
|
-
this.current =
|
|
41
|
+
this.current = track;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
44
|
+
else {
|
|
45
|
+
if (typeof offset !== "undefined" && typeof offset === "number") {
|
|
46
|
+
if (isNaN(offset)) {
|
|
47
|
+
throw new RangeError("Offset must be a number.");
|
|
48
|
+
}
|
|
49
|
+
if (offset < 0 || offset > this.length) {
|
|
50
|
+
throw new RangeError(`Offset must be between 0 and ${this.length}.`);
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(track)) {
|
|
53
|
+
this.splice(offset, 0, ...track);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.splice(offset, 0, track);
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
else {
|
|
60
|
+
if (Array.isArray(track)) {
|
|
61
|
+
this.push(...track);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.push(track);
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
|
-
if (typeof offset === "undefined" && typeof offset !== "number") {
|
|
54
|
-
if (track instanceof Array)
|
|
55
|
-
this.push(...track);
|
|
56
|
-
else
|
|
57
|
-
this.push(track);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
if (track instanceof Array)
|
|
61
|
-
this.splice(offset, 0, ...track);
|
|
62
|
-
else
|
|
63
|
-
this.splice(offset, 0, track);
|
|
64
|
-
}
|
|
65
68
|
}
|
|
66
69
|
remove(startOrPosition = 0, end) {
|
|
67
70
|
if (typeof end !== "undefined") {
|
|
68
|
-
if (isNaN(Number(startOrPosition))) {
|
|
69
|
-
throw new RangeError(`Missing "start" parameter.`);
|
|
70
|
-
}
|
|
71
|
-
else if (isNaN(Number(end))) {
|
|
72
|
-
throw new RangeError(`Missing "end" parameter.`);
|
|
73
|
-
}
|
|
74
|
-
else if (startOrPosition >= end) {
|
|
75
|
-
throw new RangeError("Start can not be bigger than end.");
|
|
71
|
+
if (isNaN(Number(startOrPosition)) || isNaN(Number(end))) {
|
|
72
|
+
throw new RangeError(`Missing "start" or "end" parameter.`);
|
|
76
73
|
}
|
|
77
|
-
|
|
78
|
-
throw new RangeError(
|
|
74
|
+
if (startOrPosition >= end || startOrPosition >= this.length) {
|
|
75
|
+
throw new RangeError("Invalid start or end values.");
|
|
79
76
|
}
|
|
80
77
|
return this.splice(startOrPosition, end - startOrPosition);
|
|
81
78
|
}
|
package/dist/structures/Rest.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Rest = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
5
6
|
/** Handles the requests sent to the Lavalink REST API. */
|
|
6
7
|
class Rest {
|
|
7
8
|
/** The ID of the current session. */
|
|
@@ -28,84 +29,47 @@ class Rest {
|
|
|
28
29
|
return this.get(`/v4/sessions/${this.sessionId}/players`);
|
|
29
30
|
}
|
|
30
31
|
/** Sends a PATCH request to update player related data. */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return request;
|
|
32
|
+
updatePlayer(options) {
|
|
33
|
+
return this.patch(`/v4/sessions/${this.sessionId}/players/${options.guildId}?noReplace=false`, options.data);
|
|
34
34
|
}
|
|
35
35
|
/** Sends a DELETE request to the server to destroy the player. */
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return request;
|
|
36
|
+
destroyPlayer(guildId) {
|
|
37
|
+
return this.delete(`/v4/sessions/${this.sessionId}/players/${guildId}`);
|
|
39
38
|
}
|
|
40
39
|
/* Sends a GET request to the specified endpoint and returns the response data. */
|
|
41
|
-
async
|
|
40
|
+
async request(method, endpoint, body) {
|
|
41
|
+
const config = {
|
|
42
|
+
method,
|
|
43
|
+
url: this.url + endpoint,
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: this.password,
|
|
47
|
+
},
|
|
48
|
+
data: body,
|
|
49
|
+
};
|
|
42
50
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
headers: {
|
|
46
|
-
"Content-Type": "application/json",
|
|
47
|
-
Authorization: this.password,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const json = await req.json();
|
|
51
|
-
return json;
|
|
51
|
+
const response = await (0, axios_1.default)(config);
|
|
52
|
+
return response.data;
|
|
52
53
|
}
|
|
53
|
-
catch
|
|
54
|
+
catch {
|
|
54
55
|
return null;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
/* Sends a GET request to the specified endpoint and returns the response data. */
|
|
59
|
+
async get(endpoint) {
|
|
60
|
+
return await this.request("GET", endpoint);
|
|
61
|
+
}
|
|
57
62
|
/* Sends a PATCH request to the specified endpoint and returns the response data. */
|
|
58
63
|
async patch(endpoint, body) {
|
|
59
|
-
|
|
60
|
-
const req = await (0, undici_1.fetch)(this.url + endpoint, {
|
|
61
|
-
method: "PATCH",
|
|
62
|
-
headers: {
|
|
63
|
-
"Content-Type": "application/json",
|
|
64
|
-
Authorization: this.password,
|
|
65
|
-
},
|
|
66
|
-
body: JSON.stringify(body),
|
|
67
|
-
});
|
|
68
|
-
const json = await req.json();
|
|
69
|
-
return json;
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
64
|
+
return await this.request("PATCH", endpoint, body);
|
|
74
65
|
}
|
|
75
66
|
/* Sends a POST request to the specified endpoint and returns the response data. */
|
|
76
67
|
async post(endpoint, body) {
|
|
77
|
-
|
|
78
|
-
const req = await (0, undici_1.fetch)(this.url + endpoint, {
|
|
79
|
-
method: "POST",
|
|
80
|
-
headers: {
|
|
81
|
-
"Content-Type": "application/json",
|
|
82
|
-
Authorization: this.password,
|
|
83
|
-
},
|
|
84
|
-
body: JSON.stringify(body),
|
|
85
|
-
});
|
|
86
|
-
const json = await req.json();
|
|
87
|
-
return json;
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
68
|
+
return await this.request("POST", endpoint, body);
|
|
92
69
|
}
|
|
93
70
|
/* Sends a DELETE request to the specified endpoint and returns the response data. */
|
|
94
71
|
async delete(endpoint) {
|
|
95
|
-
|
|
96
|
-
const req = await (0, undici_1.fetch)(this.url + endpoint, {
|
|
97
|
-
method: "DELETE",
|
|
98
|
-
headers: {
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
Authorization: this.password,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
const json = await req.json();
|
|
104
|
-
return json;
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
72
|
+
return await this.request("DELETE", endpoint);
|
|
109
73
|
}
|
|
110
74
|
}
|
|
111
75
|
exports.Rest = Rest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magmastream",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta",
|
|
4
4
|
"description": "A user-friendly Lavalink client designed for NodeJS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@discordjs/collection": "^1.5.1",
|
|
31
|
+
"axios": "^1.4.0",
|
|
31
32
|
"events": "^3.3.0",
|
|
32
33
|
"lodash": "^4.17.21",
|
|
33
34
|
"tslib": "^2.4.0",
|
|
@@ -81,6 +82,7 @@
|
|
|
81
82
|
"repository": {
|
|
82
83
|
"url": "https://github.com/Blackfort-Hosting/magmastream/tree/main"
|
|
83
84
|
},
|
|
85
|
+
"homepage": "https://docs.blackforthosting.com",
|
|
84
86
|
"author": "Abel Purnwasy",
|
|
85
87
|
"license": "Apache-2.0"
|
|
86
|
-
}
|
|
88
|
+
}
|