diff options
| author | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
| commit | dcef0b65069fb38fd0f6c4382353167f603ebff1 (patch) | |
| tree | 45954ffe308c3dd056e6af4f734e6d2af89e5856 /fig-monitor-irc/src/Fig/Monitor/IRC | |
Initial commit
Diffstat (limited to 'fig-monitor-irc/src/Fig/Monitor/IRC')
| -rw-r--r-- | fig-monitor-irc/src/Fig/Monitor/IRC/Utils.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/fig-monitor-irc/src/Fig/Monitor/IRC/Utils.hs b/fig-monitor-irc/src/Fig/Monitor/IRC/Utils.hs new file mode 100644 index 0000000..2cf46b1 --- /dev/null +++ b/fig-monitor-irc/src/Fig/Monitor/IRC/Utils.hs @@ -0,0 +1,37 @@ +{-# Language ApplicativeDo #-} + +module Fig.Monitor.IRC.Utils + ( FigMonitorIRCException(..) + , Config(..) + , loadConfig + ) where + +import Fig.Prelude + +import qualified Toml + +newtype FigMonitorIRCException = FigMonitorIRCException Text + deriving (Show, Eq, Ord) +instance Exception FigMonitorIRCException + +data Config = Config + { host :: Text + , port :: Int + , nick :: Text + , sendchannel :: Text + , channels :: [Text] + } deriving (Show, Eq, Ord) + +configCodec :: Toml.TomlCodec Config +configCodec = do + host <- Toml.text "host" Toml..= (\a -> a.host) + port <- Toml.int "port" Toml..= (\a -> a.port) + nick <- Toml.text "nick" Toml..= (\a -> a.nick) + sendchannel <- Toml.text "sendchannel" Toml..= (\a -> a.sendchannel) + channels <- Toml.arrayOf Toml._Text "channels" Toml..= (\a -> a.channels) + pure $ Config{..} + +loadConfig :: FilePath -> IO Config +loadConfig path = Toml.decodeFileEither configCodec path >>= \case + Left err -> throwM . FigMonitorIRCException $ tshow err + Right config -> pure config |
