summaryrefslogtreecommitdiff
path: root/haskell/app
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-16 23:31:00 +0200
committerJulien Dessaux2023-07-17 00:15:05 +0200
commite084d260ff0439f04ab62eba7229309d79ed55c4 (patch)
treee2355a9dad8123352474cb8533d625f87fdcde0d /haskell/app
parent[haskell] Implemented pagination and systems list api call (diff)
downloadspacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.tar.gz
spacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.tar.bz2
spacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.zip
[haskell] Add a SpaceTradersT and handle server reset api message
Diffstat (limited to 'haskell/app')
-rw-r--r--haskell/app/Main.hs37
1 files changed, 10 insertions, 27 deletions
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