summaryrefslogtreecommitdiffstats
path: root/src/Reaktor
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-04-16 14:04:38 +0200
committertv <tv@krebsco.de>2020-04-16 14:05:04 +0200
commit2bd52320dfc3bbf5d86cd74e7b76209a8cb7a330 (patch)
tree708d18cf635ce00d65400cbc653bde22c53921e8 /src/Reaktor
parent9f4e2644188f985d7cd806c13e2c0dee1688b9f0 (diff)
Reaktor.Internal: add FromJSON Message
Diffstat (limited to 'src/Reaktor')
-rw-r--r--src/Reaktor/Internal.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Reaktor/Internal.hs b/src/Reaktor/Internal.hs
index bd3d241..824c57e 100644
--- a/src/Reaktor/Internal.hs
+++ b/src/Reaktor/Internal.hs
@@ -58,6 +58,15 @@ instance FromJSON Config where
data Message = Message (Maybe Text) Command [Text] | Start
deriving Show
+instance FromJSON Message where
+ parseJSON = \case
+ Object v -> do
+ mb_prefix <- v .:? "prefix"
+ cmd <- v .: "command"
+ params <- v .: "params"
+ pure (Message mb_prefix cmd params)
+ invalid -> typeMismatch "Message" invalid
+
formatMessage :: Message -> Text
formatMessage = \case
Message mb_prefix cmd params ->