magmastream 2.9.3-dev.4 → 2.9.3-dev.6
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 +14 -3
- package/dist/structures/Player.js +1 -4
- package/dist/structures/Rest.js +41 -21
- package/dist/structures/Utils.js +23 -24
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3466,11 +3466,22 @@ declare abstract class TrackUtils {
|
|
|
3466
3466
|
static setTrackPartial(partial: TrackPartial[]): void;
|
|
3467
3467
|
/**
|
|
3468
3468
|
* Checks if the provided argument is a valid Track.
|
|
3469
|
-
*
|
|
3470
|
-
* @param trackOrTracks The Track or array of Tracks to check.
|
|
3469
|
+
* @param value The value to check.
|
|
3471
3470
|
* @returns {boolean} Whether the provided argument is a valid Track.
|
|
3472
3471
|
*/
|
|
3473
|
-
static
|
|
3472
|
+
static isTrack(track: unknown): track is Track;
|
|
3473
|
+
/**
|
|
3474
|
+
* Checks if the provided argument is a valid Track array.
|
|
3475
|
+
* @param value The value to check.
|
|
3476
|
+
* @returns {boolean} Whether the provided argument is a valid Track array.
|
|
3477
|
+
*/
|
|
3478
|
+
static isTrackArray(value: unknown): value is Track[];
|
|
3479
|
+
/**
|
|
3480
|
+
* Checks if the provided argument is a valid Track or Track array.
|
|
3481
|
+
* @param value The value to check.
|
|
3482
|
+
* @returns {boolean} Whether the provided argument is a valid Track or Track array.
|
|
3483
|
+
*/
|
|
3484
|
+
static validate(value: unknown): value is Track | Track[];
|
|
3474
3485
|
/**
|
|
3475
3486
|
* Builds a Track from the raw data from Lavalink and a optional requester.
|
|
3476
3487
|
* @param data The raw data from Lavalink to build the Track from.
|
|
@@ -806,11 +806,8 @@ class Player {
|
|
|
806
806
|
if (currentPlayingTrack) {
|
|
807
807
|
await this.queue.add(currentPlayingTrack, 0);
|
|
808
808
|
}
|
|
809
|
-
await this.play(lastTrack);
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
await this.play(lastTrack);
|
|
813
809
|
}
|
|
810
|
+
await this.play(lastTrack);
|
|
814
811
|
this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
|
|
815
812
|
changeType: Enums_1.PlayerStateEventTypes.TrackChange,
|
|
816
813
|
details: {
|
package/dist/structures/Rest.js
CHANGED
|
@@ -104,35 +104,55 @@ class Rest {
|
|
|
104
104
|
},
|
|
105
105
|
data: body,
|
|
106
106
|
timeout: this.node.options.apiRequestTimeoutMs,
|
|
107
|
+
validateStatus: () => true,
|
|
107
108
|
};
|
|
109
|
+
let response;
|
|
108
110
|
try {
|
|
109
|
-
|
|
110
|
-
return response.data;
|
|
111
|
+
response = await (0, axios_1.default)(config);
|
|
111
112
|
}
|
|
112
113
|
catch (err) {
|
|
113
|
-
const
|
|
114
|
-
if (!error.response) {
|
|
115
|
-
throw new MagmastreamError_1.MagmaStreamError({
|
|
116
|
-
code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
|
|
117
|
-
message: `No response from node ${this.node.options.identifier}: ${error.message}`,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const data = error.response.data;
|
|
121
|
-
if (data?.message === "Guild not found") {
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
if (error.response.status === 401) {
|
|
125
|
-
throw new MagmastreamError_1.MagmaStreamError({
|
|
126
|
-
code: Enums_1.MagmaStreamErrorCode.REST_UNAUTHORIZED,
|
|
127
|
-
message: `Unauthorized access to node ${this.node.options.identifier}`,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
const dataMessage = typeof data === "string" ? data : data?.message ? data.message : Utils_1.JSONUtils.safe(data, 2);
|
|
114
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
131
115
|
throw new MagmastreamError_1.MagmaStreamError({
|
|
132
116
|
code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
|
|
133
|
-
message: `
|
|
117
|
+
message: `No response from node ${this.node.options.identifier}: ${message}`,
|
|
134
118
|
});
|
|
135
119
|
}
|
|
120
|
+
const { status, data } = response;
|
|
121
|
+
if (status >= 200 && status < 300) {
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
124
|
+
// Lavalink sometimes returns "Guild not found" for inactive players
|
|
125
|
+
if (status === 404 && data?.message === "Guild not found") {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
if (status === 401) {
|
|
129
|
+
throw new MagmastreamError_1.MagmaStreamError({
|
|
130
|
+
code: Enums_1.MagmaStreamErrorCode.REST_UNAUTHORIZED,
|
|
131
|
+
message: `Unauthorized access to node ${this.node.options.identifier}`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (status >= 400 && status < 500) {
|
|
135
|
+
const message = typeof data === "string"
|
|
136
|
+
? data
|
|
137
|
+
: typeof data === "object" && data !== null && "message" in data && typeof data.message === "string"
|
|
138
|
+
? data.message
|
|
139
|
+
: "Unknown client error";
|
|
140
|
+
return {
|
|
141
|
+
status,
|
|
142
|
+
error: true,
|
|
143
|
+
message,
|
|
144
|
+
data,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const safeMessage = typeof data === "string"
|
|
148
|
+
? data
|
|
149
|
+
: typeof data === "object" && data !== null && "message" in data && typeof data.message === "string"
|
|
150
|
+
? data.message
|
|
151
|
+
: Utils_1.JSONUtils.safe(data, 2);
|
|
152
|
+
throw new MagmastreamError_1.MagmaStreamError({
|
|
153
|
+
code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
|
|
154
|
+
message: `Request to node ${this.node.options.identifier} failed (${status}): ${safeMessage}`,
|
|
155
|
+
});
|
|
136
156
|
}
|
|
137
157
|
/**
|
|
138
158
|
* Sends a GET request to the specified endpoint and returns the response data.
|
package/dist/structures/Utils.js
CHANGED
|
@@ -12,6 +12,7 @@ const MagmastreamError_1 = require("./MagmastreamError");
|
|
|
12
12
|
// import playwright from "playwright";
|
|
13
13
|
/** @hidden */
|
|
14
14
|
const SIZES = ["0", "1", "2", "3", "default", "mqdefault", "hqdefault", "maxresdefault"];
|
|
15
|
+
const REQUIRED_TRACK_KEYS = ["track", "title", "uri"];
|
|
15
16
|
class TrackUtils {
|
|
16
17
|
static trackPartial = null;
|
|
17
18
|
static manager;
|
|
@@ -39,19 +40,12 @@ class TrackUtils {
|
|
|
39
40
|
const defaultProperties = [
|
|
40
41
|
Enums_1.TrackPartial.Track,
|
|
41
42
|
Enums_1.TrackPartial.Title,
|
|
42
|
-
Enums_1.TrackPartial.Identifier,
|
|
43
43
|
Enums_1.TrackPartial.Author,
|
|
44
44
|
Enums_1.TrackPartial.Duration,
|
|
45
|
-
Enums_1.TrackPartial.Isrc,
|
|
46
|
-
Enums_1.TrackPartial.IsSeekable,
|
|
47
|
-
Enums_1.TrackPartial.IsStream,
|
|
48
45
|
Enums_1.TrackPartial.Uri,
|
|
49
|
-
Enums_1.TrackPartial.ArtworkUrl,
|
|
50
46
|
Enums_1.TrackPartial.SourceName,
|
|
51
|
-
Enums_1.TrackPartial.
|
|
47
|
+
Enums_1.TrackPartial.ArtworkUrl,
|
|
52
48
|
Enums_1.TrackPartial.Requester,
|
|
53
|
-
Enums_1.TrackPartial.PluginInfo,
|
|
54
|
-
Enums_1.TrackPartial.CustomData,
|
|
55
49
|
];
|
|
56
50
|
/** The array of property names that will be removed from the Track class */
|
|
57
51
|
this.trackPartial = Array.from(new Set([...defaultProperties, ...partial]));
|
|
@@ -61,25 +55,30 @@ class TrackUtils {
|
|
|
61
55
|
}
|
|
62
56
|
/**
|
|
63
57
|
* Checks if the provided argument is a valid Track.
|
|
64
|
-
*
|
|
65
|
-
* @param trackOrTracks The Track or array of Tracks to check.
|
|
58
|
+
* @param value The value to check.
|
|
66
59
|
* @returns {boolean} Whether the provided argument is a valid Track.
|
|
67
60
|
*/
|
|
68
|
-
static
|
|
69
|
-
if (typeof
|
|
61
|
+
static isTrack(track) {
|
|
62
|
+
if (typeof track !== "object" || track === null)
|
|
70
63
|
return false;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
const t = track;
|
|
65
|
+
return REQUIRED_TRACK_KEYS.every((key) => typeof t[key] === "string");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the provided argument is a valid Track array.
|
|
69
|
+
* @param value The value to check.
|
|
70
|
+
* @returns {boolean} Whether the provided argument is a valid Track array.
|
|
71
|
+
*/
|
|
72
|
+
static isTrackArray(value) {
|
|
73
|
+
return Array.isArray(value) && value.every(this.isTrack);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the provided argument is a valid Track or Track array.
|
|
77
|
+
* @param value The value to check.
|
|
78
|
+
* @returns {boolean} Whether the provided argument is a valid Track or Track array.
|
|
79
|
+
*/
|
|
80
|
+
static validate(value) {
|
|
81
|
+
return this.isTrack(value) || this.isTrackArray(value);
|
|
83
82
|
}
|
|
84
83
|
/**
|
|
85
84
|
* Builds a Track from the raw data from Lavalink and a optional requester.
|