~singpolyma/cheogram-muc-bridge

ref: 380691995804ec9f33b8c51b09fb674c1854d53f cheogram-muc-bridge/Config.hs -rw-r--r-- 1.2 KiB
38069199Stephen Paul Weber isGhost helper 1 year, 2 months 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.MUC(..)) 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.MUC]]
}

-- 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
		}