cheogram-muc-bridge/ConfigFile.hs

52 lines
1.3 KiB
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
module ConfigFile where
import Prelude ()
import BasicPrelude
import qualified Network
import qualified Dhall
import qualified Dhall.Core as Dhall
import qualified Network.Protocol.XMPP as XMPP
data ServerConfig = ServerConfig {
host :: Network.HostName,
port :: Network.PortID
} deriving (Dhall.Generic, Dhall.FromDhall, Show)
data MUC = MUC {
jid :: XMPP.JID,
tag :: Text,
nickChars :: Maybe String
} deriving (Dhall.Generic, Dhall.FromDhall, Show)
data Config = Config {
componentJid :: XMPP.JID,
server :: ServerConfig,
secret :: Text,
nick :: Text,
db :: Text,
mucs :: [[MUC]]
} deriving (Dhall.Generic, Dhall.FromDhall, Show)
instance Dhall.FromDhall XMPP.JID where
autoWith _ = Dhall.Decoder {
Dhall.extract = \(Dhall.TextLit (Dhall.Chunks _ txt)) ->
maybe (Dhall.extractError $ fromString "Invalid JID") pure $ XMPP.parseJID txt,
Dhall.expected = pure Dhall.Text
}
instance Dhall.FromDhall Network.PortID where
autoWith _ = Dhall.Decoder {
Dhall.extract = \(Dhall.NaturalLit nat) -> pure $ Network.PortNumber (fromIntegral nat),
Dhall.expected = pure Dhall.Natural
}
instance Dhall.FromDhall Network.PortNumber where
autoWith _ = Dhall.Decoder {
Dhall.extract = \(Dhall.NaturalLit nat) -> pure $ fromIntegral nat,
Dhall.expected = pure Dhall.Natural
}