Last active
July 6, 2020 23:28
-
-
Save GuyInGrey/0c2fe155f1b94ed279a864bfad0e464d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Message GuyInGrey if this has issues! | |
const request = require("request-promise-native"); | |
// Note: The EDSM rate limit is 360/hour. More than enough for this server's usage. | |
let apiUrl = "https://www.edsm.net/"; | |
async function getSystemInfo(systemName) { | |
return new Promise(async (fulfill, reject) => { | |
try { | |
let starSystem = await getObjectFromAPI("api-v1/system?showPrimaryStar=1&showInformation=1&showPermit=1&showId=1&systemName=" + systemName); | |
if (Array.isArray(starSystem)) { | |
return null; | |
} | |
if (starSystem.information === {}) { | |
starSystem.information = null; | |
} | |
let bodiesResponse = await getObjectFromAPI("api-system-v1/bodies?systemName=" + systemName); | |
starSystem.bodies = bodiesReponse.bodies; | |
starSystem.bodiesURL = bodiesResponse.url; | |
let stationsResponse = await getObjectFromAPI("api-system-v1/stations?systemName=" + systemName); | |
starSystem.stations = stationsResponse.stations; | |
starSystem.stationsURL = stationsResponse.url; | |
let factionsResponse = await getObjectFromAPI("api-system-v1/factions?systemName=" + systemName); | |
starSystem.factions = factionsResponse.factions; | |
starSystem.factionsURL = factionsResponse.url; | |
fulfill(system); | |
} catch (error) { reject(error); } | |
}); | |
} | |
function getEliteStatus() { | |
return new Promise(async (fulfill, reject) => { | |
try { | |
let status = await getObjectFromAPI("api-status-v1/elite-server"); | |
fulfill(status); | |
} catch (error) { reject(error); } | |
}); | |
} | |
function getObjectFromAPI(params) { | |
return new Promise(async (fulfill, reject) => { | |
try { | |
let url = apiUrl + params; | |
fulfill(JSON.parse(await request(url))); | |
} catch (error) { reject(error); } | |
}); | |
} | |
module.exports = { | |
getSystemInfo, | |
getEliteStatus, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment