diff options
author | Julien Dessaux | 2023-06-01 01:11:21 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-06-01 01:11:21 +0200 |
commit | 68c457964a02d290f3fe225b090c549d664bb836 (patch) | |
tree | 4b63ee97f5439621536594c59f25b1c35c353b37 /lib/ships.js | |
parent | Reworked the systems handling and caching with sqlite (diff) | |
download | spacetraders-68c457964a02d290f3fe225b090c549d664bb836.tar.gz spacetraders-68c457964a02d290f3fe225b090c549d664bb836.tar.bz2 spacetraders-68c457964a02d290f3fe225b090c549d664bb836.zip |
Another big refactoring
Diffstat (limited to 'lib/ships.js')
-rw-r--r-- | lib/ships.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/ships.js b/lib/ships.js index 109054c..55ee585 100644 --- a/lib/ships.js +++ b/lib/ships.js @@ -12,12 +12,14 @@ export async function extract(ctx) { default: // yet unhandled error throw response; } + } else { + await api.sleep(response.data.cooldown.remainingSeconds*1000); } return response; } export async function dock(ctx) { - const response = await api.send({endpoint: `/my/ships/${ctx.ship}/dock`, method: 'POST'}); + const response = await api.send({endpoint: `/my/ships/${ctx.symbol}/dock`, method: 'POST'}); if (response.error !== undefined) { switch(response.error.code) { case 4214: // ship is in transit @@ -48,7 +50,17 @@ export async function negotiate(ctx) { } export async function orbit(ctx) { - return await api.send({endpoint: `/my/ships/${ctx.ship}/orbit`, method: 'POST'}); + const response = await api.send({endpoint: `/my/ships/${ctx.symbol}/orbit`, method: 'POST'}); + if (response.error !== undefined) { + switch(response.error.code) { + case 4214: // ship is in transit + await api.sleep(response.error.data.secondsToArrival * 1000); + return orbit(ctx); + default: // yet unhandled error + throw response; + } + } + return response; } export async function purchase(ctx) { |