Something went wrong. Try again.
Your trusty automation assistant in TLE Community misadventures!
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import _ from 'lodash'import Table from 'cli-table3'
import { lacuna, call, colonies, eachPlanet, findBuilding, log, util,} from '@tlecommunity/super-core'
class Docks { constructor(options) { this.options = options
this.totals = [] }
handleColony(colony, buildings) { return findBuilding(buildings, 'Space Port').then((sp) => { if (!sp) { return new Promise((resolve, reject) => { reject(`No Space Port found on ${colony.name}`) }) }
return call(() => lacuna.spacePort.view({ building_id: sp.id })).then((result) => { let docks = util.int(result.max_ships) let ships = docks - util.int(result.docks_available)
this.totals.push({ name: colony.name, docks, ships, }) }) }) }
validateOptions() { return new Promise((resolve, reject) => { resolve(true) }) }
run() { return new Promise((resolve, reject) => { colonies() .then((colonies) => { return eachPlanet(colonies, _.bind(this.handleColony, this)) }) .then(() => { let table = new Table({ head: ['Planet', 'Ships', 'Docks'], })
_.each(this.totals, (total) => { table.push([total.name, util.commify(total.ships), util.commify(total.docks)]) })
table.push([ 'GRAND TOTAL', util.commify(_.sum(_.map(this.totals, 'ships'))), util.commify(_.sum(_.map(this.totals, 'docks'))), ])
log.newline() log.info(table.toString()) resolve() }) .catch(reject) }) }}
export default Docks