Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Sep 9, 2024
1 parent 4e94db0 commit a1d697c
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/main/basedbot/fleet-strategies/atlasnet-fc-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Faction, galaxySectorsData } from '../lib/util/galaxy-sectors-data'
import { nameMapMatcher } from './name-map-matcher'
import { makeStrategyMap, StrategyConfig, StrategyMap } from './strategy-config'

export const randomIntFromInterval = (min: number, max: number) => {
export const randomIntFromInterval = (min: number, max: number): number => {
return Math.floor(Math.random() * (max - min + 1) + min)
}

Expand Down Expand Up @@ -67,7 +67,7 @@ export const atlasnetFcStrategy =
.sort((a, b) => a.name.localeCompare(b.name))

for (let i = 0; i < count; i++) {
strategyMap.set(`${chance.animal()} Fleet`, {
strategyMap.set(`${chance.animal()} Fleet [${i}]`, {
fleet: getRandomFleetForFaction(player.faction),
strategy: createMiningStrategy(
mine(
Expand Down
5 changes: 3 additions & 2 deletions src/main/basedbot/fleet-strategies/get-fleet-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Game } from '@staratlas/sage'
import { Player } from '../lib/sage/state/user-account'
import { WorldMap } from '../lib/sage/state/world-map'

import { atlasnetFcStrategy } from './atlasnet-fc-strategy'
import { atlasnetLuStrategy } from './atlasnet-lu-strategy'
import { disbandAllStrategy } from './disband-all-strategy'
import { mainnetLuStrategy } from './mainnet-lu-strategy'
Expand All @@ -28,8 +29,8 @@ export const getFleetStrategy = (
// return atlasnetFcStrategy(5)(map, player, game)
return disbandAllStrategy(map, player, game)
case '34ghznSJCYEMrS1aC55UYZZUuxfuurA9441aKnigmYyz':
// return atlasnetFcStrategy(5)(map, player, game)
return disbandAllStrategy(map, player, game)
return atlasnetFcStrategy(1)(map, player, game)
// return disbandAllStrategy(map, player, game)
default:
throw new Error('Unknown strategy')
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/basedbot/fleet-strategies/number-map-matcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Strategy } from '../fsm/strategy'

import { FleetStrategy, StrategyMap } from './strategy-config'

export const numberMapMatcher =
(fallback: Strategy) =>
(key: string, strategyMap: StrategyMap): FleetStrategy => {
const fallbackFleetStrategy = {
strategy: fallback,
fleet: null,
}
const extractNumbers = (str: string): Array<number> | undefined =>
str.match(/\d+/g)?.map(Number)
const [index] = extractNumbers(key) ?? []
const mapKey = Array.from(strategyMap.keys()).find(extractNumbers)

if (!index || !mapKey) return fallbackFleetStrategy

return strategyMap.get(mapKey) || fallbackFleetStrategy
}
9 changes: 6 additions & 3 deletions src/main/basedbot/lib/fleet-state/fleet-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { isMoveSubWarpData } from './type-guard/move-sub-warp'
import { isMoveWarpData } from './type-guard/move-warp'
import { isRespawnData } from './type-guard/respawn'
import { isStarbaseLoadingBayData } from './type-guard/starbase-loading-bay'
import { FleetState, FleetStateType, RawMineAsteroidData } from './types'
import {
EndReason,
FleetState,
FleetStateType,
RawMineAsteroidData,
} from './types'

const toBig = (bn: BN): Big => new Big(bn.toString())
const toBN = (bigInt: Big): BN => new BN(bigInt.toString())
Expand Down Expand Up @@ -48,8 +53,6 @@ const calculateCurrentPosition = (
return Coordinates.fromBN(toBN(xt.round(0, 1)), toBN(yt.round(0, 1)))
}

export type EndReason = 'FULL' | 'AMMO' | 'FOOD'

type MiningStats = {
startTime: BN
endTime: BN
Expand Down
6 changes: 4 additions & 2 deletions src/main/basedbot/lib/fleet-state/type-guard/idle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import BN from 'bn.js'

import { RawIdleData } from '../types'

export const isIdleData = (data: any): data is RawIdleData =>
data &&
export const isIdleData = (data: unknown): data is RawIdleData =>
data !== undefined &&
data instanceof Object &&
'sector' in data &&
Array.isArray(data.sector) &&
data.sector.length === 2 &&
data.sector[0] instanceof BN &&
Expand Down
13 changes: 11 additions & 2 deletions src/main/basedbot/lib/fleet-state/type-guard/mine-asteroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import BN from 'bn.js'

import { RawMineAsteroidData } from '../types'

export const isMineAsteroidData = (data: any): data is RawMineAsteroidData =>
data &&
export const isMineAsteroidData = (
data: unknown,
): data is RawMineAsteroidData =>
data !== undefined &&
data instanceof Object &&
'asteroid' in data &&
'resource' in data &&
'start' in data &&
'end' in data &&
'amountMined' in data &&
'lastUpdate' in data &&
data.asteroid instanceof PublicKey &&
data.resource instanceof PublicKey &&
data.start instanceof BN &&
Expand Down
7 changes: 5 additions & 2 deletions src/main/basedbot/lib/fleet-state/type-guard/move-sub-warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import BN from 'bn.js'
import { RawMoveSubwarpData } from '../types'

// TODO: Add all the fields that are required to be present in the data
export const isMoveSubWarpData = (data: any): data is RawMoveSubwarpData =>
data &&
export const isMoveSubWarpData = (data: unknown): data is RawMoveSubwarpData =>
data !== undefined &&
data instanceof Object &&
'fromSector' in data &&
'toSector' in data &&
Array.isArray(data.fromSector) &&
data.fromSector.length === 2 &&
data.fromSector[0] instanceof BN &&
Expand Down
7 changes: 5 additions & 2 deletions src/main/basedbot/lib/fleet-state/type-guard/move-warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import BN from 'bn.js'
import { RawMoveWarpData } from '../types'

// TODO: Add all the fields that are required to be present in the data
export const isMoveWarpData = (data: any): data is RawMoveWarpData =>
data &&
export const isMoveWarpData = (data: unknown): data is RawMoveWarpData =>
data !== undefined &&
data instanceof Object &&
'fromSector' in data &&
'toSector' in data &&
Array.isArray(data.fromSector) &&
data.fromSector.length === 2 &&
data.fromSector[0] instanceof BN &&
Expand Down
6 changes: 4 additions & 2 deletions src/main/basedbot/lib/fleet-state/type-guard/respawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import BN from 'bn.js'

import { RawRespawnData } from '../types'

export const isRespawnData = (data: any): data is RawRespawnData =>
data &&
export const isRespawnData = (data: unknown): data is RawRespawnData =>
data !== undefined &&
data instanceof Object &&
'sector' in data &&
Array.isArray(data.sector) &&
data.sector.length === 2 &&
data.sector[0] instanceof BN &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import BN from 'bn.js'
import { RawStarbaseLoadingBayData } from '../types'

export const isStarbaseLoadingBayData = (
data: any,
data: unknown,
): data is RawStarbaseLoadingBayData =>
data && data.starbase instanceof PublicKey && data.lastUpdate instanceof BN
data !== undefined &&
data instanceof Object &&
'starbase' in data &&
'lastUpdate' in data &&
data.starbase instanceof PublicKey &&
data.lastUpdate instanceof BN
3 changes: 1 addition & 2 deletions src/main/basedbot/lib/fleet-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import BN from 'bn.js'
import dayjs from '../../../../dayjs'
import { Coordinates } from '../util/coordinates'

import { EndReason } from './fleet-state'

export type EndReason = 'FULL' | 'AMMO' | 'FOOD'
type BaseData = {
sector: Coordinates
warpCooldownExpiry: dayjs.Dayjs
Expand Down
13 changes: 7 additions & 6 deletions src/main/basedbot/lib/sage/act/create-fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export const createFleet = async (

const [head, ...tail] = fleetShips

const [starbasePlayer, headShip, cargoStatsDefinition] = await Promise.all([
getStarbasePlayer(player, starbase, programs),
getShipByMint(head.shipMint, game, programs),
getCargoStatsDefinition(),
])
const [starbasePlayer, headShip, [cargoStatsDefinition]] =
await Promise.all([
getStarbasePlayer(player, starbase, programs),
getShipByMint(head.shipMint, game, programs),
getCargoStatsDefinition(),
])

const createFleetReturn = createFleetIx(
player,
Expand All @@ -60,7 +61,7 @@ export const createFleet = async (
starbasePlayer,
programs,
headShip.key,
cargoStatsDefinition[0].key,
cargoStatsDefinition.key,
head.count,
name,
getShipEscrowIndex(starbasePlayer, headShip.key),
Expand Down
2 changes: 1 addition & 1 deletion src/service/sol/send-and-confirm-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const sendAndConfirmTx = async (
await confirmTx(txId)

return txId
} catch (e) {
} catch (_e) {
await sleep(500)
}
}
Expand Down

0 comments on commit a1d697c

Please sign in to comment.