summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Automation
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/src/SpaceTraders/Automation')
-rw-r--r--haskell/src/SpaceTraders/Automation/Init.hs49
1 files changed, 25 insertions, 24 deletions
diff --git a/haskell/src/SpaceTraders/Automation/Init.hs b/haskell/src/SpaceTraders/Automation/Init.hs
index 6641cf8..be3dbd2 100644
--- a/haskell/src/SpaceTraders/Automation/Init.hs
+++ b/haskell/src/SpaceTraders/Automation/Init.hs
@@ -5,23 +5,24 @@ module SpaceTraders.Automation.Init
, initST
) where
-import Control.Exception
-import Control.Monad.Reader
-import qualified Database.SQLite.Simple as S
-import qualified Data.Text as T
-import System.Directory
+import Control.Exception
+import Control.Monad.Error.Class
+import Control.Monad.Reader
+import qualified Data.Text as T
+import qualified Database.SQLite.Simple as S
+import System.Directory
-import SpaceTraders
-import SpaceTraders.APIClient.Agent
-import SpaceTraders.APIClient.Client
-import SpaceTraders.APIClient.Contracts
-import SpaceTraders.APIClient.Errors
-import SpaceTraders.APIClient.Ships
-import SpaceTraders.Database
-import SpaceTraders.Database.Agents
-import SpaceTraders.Database.Contracts
-import SpaceTraders.Database.Ships
-import SpaceTraders.Database.Tokens
+import SpaceTraders
+import SpaceTraders.APIClient.Agent
+import SpaceTraders.APIClient.Client
+import SpaceTraders.APIClient.Contracts
+import SpaceTraders.APIClient.Errors
+import SpaceTraders.APIClient.Ships
+import SpaceTraders.Database
+import SpaceTraders.Database.Agents
+import SpaceTraders.Database.Contracts
+import SpaceTraders.Database.Ships
+import SpaceTraders.Database.Tokens
deinitST :: Env -> IO ()
deinitST env = do
@@ -30,7 +31,7 @@ deinitST env = do
initST :: IO Env
initST = do
conn <- open
- t <- runReaderT getToken conn `catch` handleNoToken conn
+ t <- runReaderT getToken conn `catchError` handleNoToken conn
env <- newEnv conn (tokenReq t)
ma <- runReaderT getAgent conn -- We compare the agent state in the database
ma' <- runSpaceTradersT myAgent env -- with the one on the servers
@@ -42,21 +43,21 @@ initST = do
_ <- runReaderT myContracts env -- refresh contracts
_ <- runReaderT myShips env -- refresh ships
runReaderT (setAgent ma'') conn -- store the fresh agent state
- return $ env
+ return env
where
- handleNoToken :: S.Connection -> SomeException -> IO T.Text
+ handleNoToken :: S.Connection -> IOException -> IO T.Text
handleNoToken conn _ = newEnv conn defaultReq >>= runReaderT registerST
-registerST :: SpaceTradersT (T.Text)
+registerST :: SpaceTradersT T.Text
registerST = do
- r <- register "ADYXAX-HS" "COSMIC"
+ r <- register "ADYXAX-HS-6" "COSMIC"
case r of
Right r' -> do
let t = token r'
addToken t
- addAgent $ agent r'
- addContract $ contract r'
- addShip $ ship r'
+ setAgent $ agent r'
+ setContract $ contract r'
+ setShip $ ship r'
return t
Left e' -> throw e'