summaryrefslogtreecommitdiff
path: root/Network/API/Telegram/Bot/Object/Update/Moving.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Network/API/Telegram/Bot/Object/Update/Moving.hs')
-rw-r--r--Network/API/Telegram/Bot/Object/Update/Moving.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Network/API/Telegram/Bot/Object/Update/Moving.hs b/Network/API/Telegram/Bot/Object/Update/Moving.hs
new file mode 100644
index 0000000..e25b9d3
--- /dev/null
+++ b/Network/API/Telegram/Bot/Object/Update/Moving.hs
@@ -0,0 +1,30 @@
+module Network.API.Telegram.Bot.Object.Update.Moving (Moving (..)) where
+
+import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))
+import "aeson" Data.Aeson.Types (Object, Parser)
+import "base" Control.Applicative ((<*>), (<|>))
+import "base" Control.Monad ((>>=))
+import "base" Data.Function (($))
+import "base" Data.Functor ((<$>))
+import "base" Data.Int (Int64)
+import "base" Text.Show (Show)
+import "text" Data.Text (Text)
+
+import Network.API.Telegram.Bot.Object.Sender (Sender)
+
+data Moving
+ = Gone Sender (Int64, Text)
+ | Joined [Sender] (Int64, Text)
+ deriving Show
+
+instance FromJSON Moving where
+ parseJSON = withObject "Moving" $ \v -> gone v <|> joined v where
+
+ gone :: Object -> Parser Moving
+ gone v = Gone <$> v .: "left_chat_member" <*> (v .: "chat" >>= chat)
+
+ joined :: Object -> Parser Moving
+ joined v = Joined <$> v .: "new_chat_members" <*> (v .: "chat" >>= chat)
+
+ chat :: Object -> Parser (Int64, Text)
+ chat c = (,) <$> c .: "id" <*> c .: "title"