{-# LANGUAGE OverloadedStrings #-} module IrcBot.JsonConfigDecoder where import Data.Aeson import Network.Socket import qualified Data.ByteString.Lazy as C import IrcBot.Definitions.Options import IrcBot.Definitions.ServerAddress import GHC.Generics instance FromJSON IServerAddress where parseJSON = withObject "IServerAddress" $ \o -> do server_ <- o .: "server" port_ <- o .: "port" ssl_ <- o .: "ssl" nickname_ <- o .: "nickname" password_ <- o .: "password" channels_ <- o .: "channels" return $ IServerAddress server_ port_ ssl_ nickname_ password_ channels_ instance FromJSON IOptions where parseJSON = withObject "IOptions" $ \o -> do admins_ <- o .: "admins" servers_ <- o .: "servers" return $ IOptions admins_ servers_ instance ToJSON IServerAddress instance ToJSON IOptions --readConfigFile :: Maybe IServerAddress --readConfigFile = C.readFile ".connection.json" >>= \output -> decode output :: Maybe IServerAddress