Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

42 lines
1017B

  1. {-# LANGUAGE OverloadedStrings #-}
  2. module IrcBot.JsonConfigDecoder where
  3. import Data.Aeson
  4. import Network.Socket
  5. import qualified Data.ByteString.Lazy as C
  6. import IrcBot.Definitions.Options
  7. import IrcBot.Definitions.ServerAddress
  8. import GHC.Generics
  9. instance FromJSON IServerAddress where
  10. parseJSON = withObject "IServerAddress" $ \o -> do
  11. server_ <- o .: "server"
  12. port_ <- o .: "port"
  13. ssl_ <- o .: "ssl"
  14. nickname_ <- o .: "nickname"
  15. password_ <- o .: "password"
  16. channels_ <- o .: "channels"
  17. return $ IServerAddress server_ port_ ssl_ nickname_ password_ channels_
  18. instance FromJSON IOptions where
  19. parseJSON = withObject "IOptions" $ \o -> do
  20. admins_ <- o .: "admins"
  21. servers_ <- o .: "servers"
  22. return $ IOptions admins_ servers_
  23. instance ToJSON IServerAddress
  24. instance ToJSON IOptions
  25. --readConfigFile :: Maybe IServerAddress
  26. --readConfigFile = C.readFile ".connection.json" >>= \output -> decode output :: Maybe IServerAddress