summaryrefslogtreecommitdiff
path: root/haskell/app
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-02 22:58:30 +0200
committerJulien Dessaux2023-07-02 23:01:01 +0200
commita775330b4fa17fb367e55343e6fda6c7ae9e34b4 (patch)
tree8c572f799dbf434459d4659e32559c121421f120 /haskell/app
parentMoved the nodejs agent to its own subfolder to make room for my haskell agent (diff)
downloadspacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.tar.gz
spacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.tar.bz2
spacetraders-a775330b4fa17fb367e55343e6fda6c7ae9e34b4.zip
Bootstrapped my haskell client
Diffstat (limited to '')
-rw-r--r--haskell/app/Main.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs
new file mode 100644
index 0000000..32aa908
--- /dev/null
+++ b/haskell/app/Main.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+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.Database
+import SpaceTraders.Database.Agents
+import SpaceTraders.Database.Tokens
+
+main :: IO ()
+main = do
+ conn <- open
+ t <- getToken conn `catch` registerNow conn
+ ma <- myAgent t
+ print ma
+ 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'
+ let t = token r'
+ setToken conn $ t
+ return t
+ Left e' -> throwIO e'