summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api.js2
-rw-r--r--lib/contracts.js6
-rw-r--r--lib/ships.js15
-rw-r--r--lib/systems.js19
4 files changed, 37 insertions, 5 deletions
diff --git a/lib/api.js b/lib/api.js
index 1519888..a531980 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -9,7 +9,7 @@ let queue = new PriorityQueue(); // a priority queue to hold api calls we want t
// send takes a request object as argument and an optional context ctx
// example request: {
-// endpoint: the url endpoint to call,
+// endpoint: the path part of the url to call,
// method: HTTP method for `fetch` call, defaults to 'GET',
// payload: optional json object that will be send along with the request,
// priority: optional priority value (defaults to 10, lower than 10 means the message will be sent faster)
diff --git a/lib/contracts.js b/lib/contracts.js
index 9494595..a118ae4 100644
--- a/lib/contracts.js
+++ b/lib/contracts.js
@@ -1,7 +1,7 @@
import * as api from './api.js';
export async function accept(ctx) {
- return await api.send({endpoint: `/my/contracts/${ctx.id}/accept`, method: 'POST'});
+ return await api.send({endpoint: `/my/contracts/${ctx.contract}/accept`, method: 'POST'});
}
export async function contracts() {
@@ -15,3 +15,7 @@ export async function deliver(ctx) {
units: ctx.units,
}});
}
+
+export async function fulfill(ctx) {
+ return await api.send({ endpoint: `/my/contracts/${ctx.contract}/fulfill`, method: 'POST'});
+}
diff --git a/lib/ships.js b/lib/ships.js
index 6eefd87..109054c 100644
--- a/lib/ships.js
+++ b/lib/ships.js
@@ -30,10 +30,21 @@ export async function dock(ctx) {
return response;
}
+export async function jump(ctx) {
+ const response = await api.send({endpoint: `/my/ships/${ctx.ship}/jump`, method: 'POST', payload: { systemSymbol: ctx.system }});
+ await api.sleep(response.data.cooldown.remainingSeconds*1000);
+ return response;
+}
+
export async function navigate(ctx) {
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);
+ return response;
+}
+
+export async function negotiate(ctx) {
+ return await api.send({endpoint: `/my/ships/${ctx.ship}/negotiate/contract`, method: 'POST'});
}
export async function orbit(ctx) {
@@ -58,3 +69,7 @@ export async function sell(ctx) {
export async function ship(ctx) {
return await api.send({endpoint: `/my/ships/${ctx.ship}`});
}
+
+export async function survey(ctx) {
+ return await api.send({endpoint: `/my/ships/${ctx.ship}/survey`, method: 'POST'});
+}
diff --git a/lib/systems.js b/lib/systems.js
index ad354e4..4b480de 100644
--- a/lib/systems.js
+++ b/lib/systems.js
@@ -3,18 +3,18 @@ import * as db from '../database/systems.js';
// Retrieves a list of waypoints that have a specific ctx.trait like a SHIPYARD or a MARKETPLACE in the system ctx.symbol
export async function trait(ctx) {
- const s = await getSystem(ctx);
+ const s = await system(ctx);
return s.filter(s => s.traits.some(t => t.symbol === ctx.trait));
}
// Retrieves a list of waypoints that have a specific ctx.type like ASTEROID_FIELD in the system ctx.symbol
export async function type(ctx, response) {
- const s = await getSystem(ctx);
+ const s = await system(ctx);
return s.filter(s => s.type === ctx.type);
}
// Retrieves the system's information for ctx.symbol and cache it in the database
-async function getSystem(ctx) {
+export async function system(ctx) {
let s = db.getSystem(ctx.symbol);
if (s === null) {
const response = await api.send({endpoint: `/systems/${ctx.symbol}/waypoints?limit=20&page=1`});
@@ -34,3 +34,16 @@ async function getSystem(ctx) {
}
return s;
}
+
+export async function systems(ctx) {
+ const response = await api.send({endpoint: `/systems?limit=20&page=1`});
+ // TODO pagination
+ return response;
+}
+
+// Retrieves a shipyard's information for ctx.symbol
+export async function shipyard(ctx) {
+ const systemSymbol = ctx.symbol.match(/([^-]+-[^-]+)/)[1]; // TODO generalise this extraction
+ console.log(systemSymbol);
+ return await api.send({endpoint: `/systems/${systemSymbol}/waypoints/${ctx.symbol}/shipyard`});
+}