-- | Config.hs
-- A module which parse config file and contain Config structure for
-- further usage.
module Config (
Config(..),
readConfig
) where
import Data.ConfigFile
import System.Directory
import Control.Monad.Error
-- | Config structure.
data Config = Config
{ cusername :: String
, cpassword :: String
, cserver :: String
, cconference :: String
, cnickname :: String
, cprivateKey :: String
, csite :: String
, curlAdd :: String
} deriving Show
-- | Read config file in home directory and return conf structure.
readConfig :: String -> IO Config
readConfig filePath = do
home <- getHomeDirectory
config <- runErrorT $ do
conf <- join $ liftIO $ readfile emptyCP (home++"/"++filePath)
let param = get conf "bot"
liftM Config (param "username") `ap`
(param "password") `ap`
(param "server") `ap`
(param "conference") `ap`
(param "nickname") `ap`
(param "privatekey") `ap`
(param "site") `ap`
(param "urladd")
case config of
Left e -> error $ "Can't parse config file.\n"++show e
Right conf -> return conf