~singpolyma/cheogram-muc-bridge

cheogram-muc-bridge/ConfigFile.hs -rw-r--r-- 1.4 KiB
caf03566Stephen Paul Weber Use non-extra-payload algorthm for rooms that don't support it 2 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
51
52
53
{-# 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 :: Maybe Text,
	nickChars :: Maybe String,
	nickLength :: Maybe Dhall.Natural,
	extraPresencePayloads :: Bool
} 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
		}