~singpolyma/cheogram-muc-bridge

ref: d0cf3b4b11a688898b3937af239e2c58ab85841a cheogram-muc-bridge/Config.hs -rw-r--r-- 1.3 KiB
d0cf3b4bStephen Paul Weber Initial commit 1 year, 10 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

module Config where

import Prelude ()
import BasicPrelude

import qualified Network
import qualified Dhall
import qualified Dhall.Core as Dhall
import qualified Network.Protocol.XMPP as XMPP

import Util

data ServerConfig = ServerConfig {
	host :: Network.HostName,
	port :: Network.PortID
} deriving (Dhall.Generic, Dhall.FromDhall, Show)

data Bridge = Bridge {
	muc1 :: XMPP.JID,
	muc2 :: XMPP.JID
} deriving (Dhall.Generic, Dhall.FromDhall, Show)

data Config = Config {
	componentJid :: XMPP.JID,
	server :: ServerConfig,
	secret :: Text,
	mucs :: [Bridge]
} 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 $ s"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
		}