~singpolyma/cheogram-muc-bridge

cheogram-muc-bridge/Config.hs -rw-r--r-- 1.2 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
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
		}