blob: 6925b844e4bb8e9939b4890afb8c9fa8cb709393 (
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
|
{-# Language ApplicativeDo #-}
module Fig.Monitor.Discord.Utils
( FigMonitorDiscordException(..)
, Config(..)
, loadConfig
) where
import Fig.Prelude
import qualified Toml
newtype FigMonitorDiscordException = FigMonitorDiscordException Text
deriving (Show, Eq, Ord)
instance Exception FigMonitorDiscordException
data Config = Config
{ authToken :: !Text
, guildIds :: ![Integer]
} deriving (Show, Eq, Ord)
configCodec :: Toml.TomlCodec Config
configCodec = do
authToken <- Toml.text "auth_token" Toml..= (\a -> a.authToken)
guildIds <- Toml.arrayOf Toml._Integer "guild_ids" Toml..= (\a -> a.guildIds)
pure $ Config{..}
loadConfig :: FilePath -> IO Config
loadConfig path = Toml.decodeFileEither configCodec path >>= \case
Left err -> throwM . FigMonitorDiscordException $ tshow err
Right config -> pure config
|