erlc-api 2.3.4 → 3.0.0
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/.gitattributes +2 -2
- package/README.md +428 -110
- package/package.json +36 -34
- package/src/classes/client.js +35 -35
- package/src/constants.js +1 -1
- package/src/erlc.js +15 -14
- package/src/functions/assert.js +4 -4
- package/src/functions/server/getBans.js +54 -28
- package/src/functions/server/getCommandLogs.js +54 -28
- package/src/functions/server/getJoinLogs.js +54 -28
- package/src/functions/server/getKillLogs.js +54 -28
- package/src/functions/server/getModcallLogs.js +54 -28
- package/src/functions/server/getPlayers.js +54 -28
- package/src/functions/server/getQueue.js +54 -28
- package/src/functions/server/getServer.js +77 -51
- package/src/functions/server/getStaff.js +54 -0
- package/src/functions/server/getVehicles.js +54 -28
- package/src/functions/server/runCommand.js +70 -29
- package/src/types/custom.d.ts +4 -4
- package/src/types/index.d.ts +98 -91
package/src/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
exports.Vanity = "https://policeroleplay.community/join?code="
|
|
1
|
+
exports.Vanity = "https://policeroleplay.community/join?code="
|
|
2
2
|
exports.BASEURL = "https://api.policeroleplay.community/v1"
|
package/src/erlc.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
exports.config = {};
|
|
2
|
-
|
|
3
|
-
exports.getBans = require("./functions/server/getBans.js");
|
|
4
|
-
exports.getCommandLogs = require("./functions/server/getCommandLogs.js");
|
|
5
|
-
exports.getJoinLogs = require("./functions/server/getJoinLogs.js");
|
|
6
|
-
exports.getKillLogs = require("./functions/server/getKillLogs.js");
|
|
7
|
-
exports.getModcallLogs = require("./functions/server/getModcallLogs.js");
|
|
8
|
-
exports.getPlayers = require("./functions/server/getPlayers.js");
|
|
9
|
-
exports.getServer = require("./functions/server/getServer.js");
|
|
10
|
-
exports.getQueue = require("./functions/server/getQueue.js");
|
|
11
|
-
exports.runCommand = require("./functions/server/runCommand.js");
|
|
12
|
-
exports.getVehicles = require("./functions/server/getVehicles.js");
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
exports.config = {};
|
|
2
|
+
|
|
3
|
+
exports.getBans = require("./functions/server/getBans.js");
|
|
4
|
+
exports.getCommandLogs = require("./functions/server/getCommandLogs.js");
|
|
5
|
+
exports.getJoinLogs = require("./functions/server/getJoinLogs.js");
|
|
6
|
+
exports.getKillLogs = require("./functions/server/getKillLogs.js");
|
|
7
|
+
exports.getModcallLogs = require("./functions/server/getModcallLogs.js");
|
|
8
|
+
exports.getPlayers = require("./functions/server/getPlayers.js");
|
|
9
|
+
exports.getServer = require("./functions/server/getServer.js");
|
|
10
|
+
exports.getQueue = require("./functions/server/getQueue.js");
|
|
11
|
+
exports.runCommand = require("./functions/server/runCommand.js");
|
|
12
|
+
exports.getVehicles = require("./functions/server/getVehicles.js");
|
|
13
|
+
exports.getStaff = require("./functions/server/getStaff.js");
|
|
14
|
+
|
|
15
|
+
exports.Client = require("./classes/client.js");
|
package/src/functions/assert.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = function(condition, message) {
|
|
2
|
-
if (!condition) {
|
|
3
|
-
throw new Error(message);
|
|
4
|
-
}
|
|
1
|
+
module.exports = function(condition, message) {
|
|
2
|
+
if (!condition) {
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
}
|
|
5
5
|
}
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the list of banned players from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Object>} Promise that resolves to banned players object
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/bans`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(data || {});
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves command logs from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of command logs
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/commandlogs`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves join/leave logs from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of join logs
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/joinlogs`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves kill logs from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of kill logs
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/killlogs`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves moderator call logs from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of modcall logs
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/modcalls`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves current players from a server
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of current players
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/players`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -1,28 +1,54 @@
|
|
|
1
|
-
const { BASEURL } = require("../../constants.js");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
const { BASEURL } = require("../../constants.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves server queue information
|
|
5
|
+
* @param {string} serverToken - The server API key
|
|
6
|
+
* @returns {Promise<Array>} Promise that resolves to array of queued player IDs
|
|
7
|
+
*/
|
|
8
|
+
module.exports = (serverToken) => {
|
|
9
|
+
return new Promise(async (resolve, reject) => {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!serverToken || typeof serverToken !== 'string') {
|
|
12
|
+
return reject(new Error('Server token is required and must be a string'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const fetch = await import("node-fetch");
|
|
17
|
+
const { config } = await import("../../erlc.js");
|
|
18
|
+
|
|
19
|
+
// Check if global token is configured
|
|
20
|
+
if (!config?.globalToken) {
|
|
21
|
+
return reject(new Error('Global token not configured. Please initialize the client first.'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const res = await fetch.default(`${BASEURL}/server/queue`, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": config.globalToken,
|
|
27
|
+
"Server-Key": serverToken,
|
|
28
|
+
},
|
|
29
|
+
timeout: 10000, // 10 second timeout
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
const errorData = await res.json().catch(() => ({ error: 'Unknown API error' }));
|
|
34
|
+
const error = new Error(`API Error: ${res.status} - ${errorData.error || res.statusText}`);
|
|
35
|
+
error.status = res.status;
|
|
36
|
+
error.data = errorData;
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
resolve(Array.isArray(data) ? data : []);
|
|
42
|
+
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Handle different types of errors
|
|
45
|
+
if (error.code === 'ENOTFOUND') {
|
|
46
|
+
reject(new Error('Network error: Unable to connect to ER:LC API'));
|
|
47
|
+
} else if (error.name === 'AbortError') {
|
|
48
|
+
reject(new Error('Request timeout: API took too long to respond'));
|
|
49
|
+
} else {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|