blob: 7a33b05be6897c97bab57b5b5a450436c6d06231 (
plain)
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
|
{-# Language RecordWildCards #-}
{-# Language ApplicativeDo #-}
module Fig.Monitor.Twitch.Utils
( FigMonitorTwitchException(..)
, loadConfig
, Config(..)
) where
import Fig.Prelude
import qualified Toml
newtype FigMonitorTwitchException = FigMonitorTwitchException Text
deriving (Show, Eq, Ord)
instance Exception FigMonitorTwitchException
data Config = Config
{ clientId :: Text
, clientSecret :: Text
, userToken :: Text
, userLogin :: Text
, monitor :: [Text]
} deriving (Show, Eq, Ord)
configCodec :: Toml.TomlCodec Config
configCodec = do
clientId <- Toml.text "client_id" Toml..= (\a -> a.clientId)
clientSecret <- Toml.text "client_secret" Toml..= (\a -> a.clientSecret)
userToken <- Toml.text "user_token" Toml..= (\a -> a.userToken)
userLogin <- Toml.text "user_login" Toml..= (\a -> a.userLogin)
monitor <- Toml.arrayOf Toml._Text "monitor" Toml..= (\a -> a.monitor)
pure $ Config{..}
loadConfig :: FilePath -> IO Config
loadConfig path = Toml.decodeFileEither configCodec path >>= \case
Left err -> throwM . FigMonitorTwitchException $ tshow err
Right config -> pure config
|