1
0
Fork 0

Bootstrapped my haskell client

This commit is contained in:
Julien Dessaux 2023-07-02 22:58:30 +02:00
parent 36cc33f9e9
commit a775330b4f
Signed by: adyxax
GPG key ID: F92E51B86E07177E
12 changed files with 389 additions and 2 deletions

31
haskell/app/Main.hs Normal file
View file

@ -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'