~singpolyma/cheogram-muc-bridge

ref: 27ee019deca4ac0d11da318f6e8204995ed7ac97 cheogram-muc-bridge/Config.hs -rw-r--r-- 1.2 KiB
27ee019dStephen Paul Weber Allow Config to contain more than just the raw config file 2 years 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
module Config (setup, Config(..), ConfigFile.ServerConfig(..), ConfigFile.Bridge(..)) where

import Prelude ()
import BasicPrelude

import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Dhall
import qualified Network.Protocol.XMPP as XMPP
import qualified Database.SQLite.Simple as DB

import qualified ConfigFile

data Config = Config {
	componentJid :: XMPP.JID,
	server :: ConfigFile.ServerConfig,
	secret :: Text,
	nick :: Text,
	bridgeJid :: XMPP.JID,
	db :: DB.Connection,
	dbVersion :: Integer,
	mucs :: [ConfigFile.Bridge]
}

-- Not importing Util because Util imports us
s :: (IsString s) => String -> s
s = fromString

setup :: Text -> IO Config
setup expr = do
	configFile <- Dhall.input Dhall.auto expr
	Just bridgeJid <- return $ XMPP.parseJID $ s"bridge@" ++
		XMPP.formatJID (ConfigFile.componentJid configFile) ++ s"/bridge"
	db <- DB.open (textToString $ ConfigFile.db configFile)
	now <- getPOSIXTime
	return $ Config {
			componentJid = ConfigFile.componentJid configFile,
			server = ConfigFile.server configFile,
			secret = ConfigFile.secret configFile,
			nick = ConfigFile.nick configFile,
			bridgeJid = bridgeJid,
			db = db,
			dbVersion = ceiling now,
			mucs = ConfigFile.mucs configFile
		}