From e084d260ff0439f04ab62eba7229309d79ed55c4 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 16 Jul 2023 23:31:00 +0200 Subject: [haskell] Add a SpaceTradersT and handle server reset api message --- haskell/app/Main.hs | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'haskell/app') diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 38e6b0d..e22988c 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -3,36 +3,19 @@ module Main (main) where import Control.Exception -import qualified Database.SQLite.Simple as S -import qualified Data.Text as T -import SpaceTraders.APIClient.Agent +import SpaceTraders +import SpaceTraders.Automation.Init +import SpaceTraders.APIClient.Agent(myAgent) import SpaceTraders.APIClient.Systems -import SpaceTraders.Database -import SpaceTraders.Database.Agents -import SpaceTraders.Database.Contracts -import SpaceTraders.Database.Ships -import SpaceTraders.Database.Tokens main :: IO () main = do - conn <- open - t <- getToken conn `catch` registerNow conn - ma <- myAgent t + config <- initST + ma <- runSpaceTradersT myAgent config print ma - s <- listSystems t conn - print s - close conn - where - registerNow :: S.Connection -> SomeException -> IO (T.Text) - registerNow conn _ = do - r <- register "ADYXAX" "COSMIC" - case r of - Right r' -> do - setAgent conn $ agent r' - addContract conn $ contract r' - addShip conn $ ship r' - let t = token r' - setToken conn $ t - return t - Left e' -> throwIO e' + s <- listSystems (token config) (conn config) + case s of + Left e -> throwIO e + Right s' -> print $ length s' + deinitST config -- cgit v1.2.3