summaryrefslogtreecommitdiff
path: root/lib/ships.js
diff options
context:
space:
mode:
authorJulien Dessaux2023-05-26 00:04:16 +0200
committerJulien Dessaux2023-05-26 00:04:16 +0200
commit19107b153e9e3a5e4a758b9db6a867c031467320 (patch)
tree1d45818111db9903f2976ca323357347d1b25a61 /lib/ships.js
parentUpdated the lib for the new api (diff)
downloadspacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.tar.gz
spacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.tar.bz2
spacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.zip
Automated the extraction and delivery loop for a ship
Diffstat (limited to '')
-rw-r--r--lib/ships.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/ships.js b/lib/ships.js
index 9a57c12..6eefd87 100644
--- a/lib/ships.js
+++ b/lib/ships.js
@@ -5,7 +5,7 @@ export async function extract(ctx) {
if (response.error !== undefined) {
switch(response.error.code) {
case 4000: // ship is on cooldown
- await api.sleep(response.error.data.remainingSeconds * 1000);
+ await api.sleep(response.error.data.cooldown.remainingSeconds * 1000);
return extract(ctx);
case 4228: // ship is full
return null;
@@ -31,7 +31,9 @@ export async function dock(ctx) {
}
export async function navigate(ctx) {
- return await api.send({endpoint: `/my/ships/${ctx.ship}/navigate`, method: 'POST', payload: { waypointSymbol: ctx.waypoint }});
+ const response = await api.send({endpoint: `/my/ships/${ctx.ship}/navigate`, method: 'POST', payload: { waypointSymbol: ctx.waypoint }});
+ const delay = new Date(response.data.nav.route.arrival) - new Date();
+ await api.sleep(delay);
}
export async function orbit(ctx) {