Skip to content

Commit fc76298

Browse files
committed
refactoring commands. add DuplicateRecordFields extension. rename all fields
1 parent 0cb6203 commit fc76298

12 files changed

Lines changed: 216 additions & 219 deletions
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE OverloadedStrings #-}
34

4-
module Aitu.Bot.Commands.ChangeGroupAvatar (ChangeGroupAvatar (..)) where
5+
module Aitu.Bot.Commands.ChangeGroupAvatar
6+
( ChangeGroupAvatar(..)
7+
)
8+
where
59

6-
import Data.Aeson
7-
import Data.Maybe
8-
import Data.Text
9-
import Data.UUID.Types
10+
import Data.Aeson
11+
import Data.Maybe
12+
import Data.Text
13+
import Data.UUID.Types
1014

11-
import Aitu.Bot.Types.Peer (Peer)
15+
import Aitu.Bot.Types.Peer ( Peer )
1216

1317
-- doc: https://btsdigital.github.io/bot-api-contract/ChangeGroupAvatar.html
1418
data ChangeGroupAvatar = ChangeGroupAvatar {
15-
changeGroupAvatarType :: Text
16-
, changeGroupAvatarGroupId :: UUID
17-
, changeGroupAvatarFileId :: UUID
19+
groupId :: UUID
20+
, fileId :: UUID
1821
} deriving (Show)
1922

2023
instance ToJSON ChangeGroupAvatar where
21-
toJSON command = object [
22-
"type" .= changeGroupAvatarType command
23-
, "groupId" .= changeGroupAvatarGroupId command
24-
, "fileId" .= changeGroupAvatarFileId command]
25-
26-
instance FromJSON ChangeGroupAvatar where
27-
parseJSON (Object o) = ChangeGroupAvatar <$> o .: "type"
28-
<*> o .: "groupId"
29-
<*> o .: "fileId"
24+
toJSON ChangeGroupAvatar {..} = object
25+
[ "type" .= ("ChangeGruopAvatar" :: Text)
26+
, "groupId" .= groupId
27+
, "fileId" .= fileId
28+
]
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
13
{-# LANGUAGE OverloadedStrings #-}
24

3-
module Aitu.Bot.Commands.ChangeGroupDescription (ChangeGroupDescription (..)) where
5+
module Aitu.Bot.Commands.ChangeGroupDescription
6+
( ChangeGroupDescription(..)
7+
)
8+
where
49

5-
import Data.Aeson
6-
import Data.Maybe
7-
import Data.Text
8-
import Data.UUID.Types
10+
import Data.Aeson
11+
import Data.Maybe
12+
import Data.Text
13+
import Data.UUID.Types
914

10-
import Aitu.Bot.Types.Peer (Peer)
15+
import Aitu.Bot.Types.Peer ( Peer )
1116

1217
-- doc: https://btsdigital.github.io/bot-api-contract/ChangeGroupDescription.html
1318
data ChangeGroupDescription = ChangeGroupDescription {
14-
changeGroupDescriptionGroupType :: Text
15-
, changeGroupDescriptionGroupId :: UUID
16-
, changeGroupDescriptionDescription :: Text
19+
groupId :: UUID
20+
, description :: Text
1721
} deriving (Show)
1822

1923
instance ToJSON ChangeGroupDescription where
20-
toJSON command = object [
21-
"type" .= changeGroupDescriptionGroupType command
22-
, "groupId" .= changeGroupDescriptionGroupId command
23-
, "description" .= changeGroupDescriptionDescription command]
24-
25-
instance FromJSON ChangeGroupDescription where
26-
parseJSON (Object o) = ChangeGroupDescription <$> o .: "type"
27-
<*> o .: "groupId"
28-
<*> o .: "title"
24+
toJSON ChangeGroupDescription {..} = object
25+
[ "type" .= ("ChangeGroupDescription" :: Text)
26+
, "groupId" .= groupId
27+
, "description" .= description
28+
]
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
13
{-# LANGUAGE OverloadedStrings #-}
24

3-
module Aitu.Bot.Commands.ChangeGroupTitle (ChangeGroupTitle (..)) where
5+
module Aitu.Bot.Commands.ChangeGroupTitle
6+
( ChangeGroupTitle(..)
7+
)
8+
where
49

5-
import Data.Aeson
6-
import Data.Maybe
7-
import Data.Text
8-
import Data.UUID.Types
10+
import Data.Aeson
11+
import Data.Maybe
12+
import Data.Text
13+
import Data.UUID.Types
914

10-
import Aitu.Bot.Types.Peer (Peer)
15+
import Aitu.Bot.Types.Peer ( Peer )
1116

12-
-- doc: https://btsdigital.github.io/bot-api-contract/KickFromGroup.html
17+
type Title = Text
18+
19+
-- doc: https://btsdigital.github.io/bot-api-contract/ChangeGroupTitle.html
1320
data ChangeGroupTitle = ChangeGroupTitle {
14-
changeGroupTitleGroupType :: Text
15-
, changeGroupTitleGroupId :: UUID
16-
, changeGroupTitleTitle :: Text
21+
groupId :: UUID
22+
, title :: Title
1723
} deriving (Show)
1824

1925
instance ToJSON ChangeGroupTitle where
20-
toJSON command = object [
21-
"type" .= changeGroupTitleGroupType command
22-
, "groupId" .= changeGroupTitleGroupId command
23-
, "title" .= changeGroupTitleTitle command]
24-
25-
instance FromJSON ChangeGroupTitle where
26-
parseJSON (Object o) = ChangeGroupTitle <$> o .: "type"
27-
<*> o .: "groupId"
28-
<*> o .: "title"
26+
toJSON ChangeGroupTitle {..} = object
27+
[ "type" .= ("ChangeGroupTitle" :: Text)
28+
, "groupId" .= groupId
29+
, "title" .= title
30+
]
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE OverloadedStrings #-}
34

4-
module Aitu.Bot.Commands.DeleteGroupAvatar (DeleteGroupAvatar (..)) where
5+
module Aitu.Bot.Commands.DeleteGroupAvatar
6+
( DeleteGroupAvatar(..)
7+
)
8+
where
59

6-
import Data.Aeson
7-
import Data.Maybe
8-
import Data.Text
9-
import Data.UUID.Types
10+
import Data.Aeson
11+
import Data.Maybe
12+
import Data.Text
13+
import Data.UUID.Types
1014

11-
import Aitu.Bot.Types.Peer (Peer)
15+
import Aitu.Bot.Types.Peer ( Peer )
1216

1317
-- doc: https://btsdigital.github.io/bot-api-contract/DeleteGroupAvatar.html
14-
data DeleteGroupAvatar = DeleteGroupAvatar {
15-
deleteGroupAvatarType :: Text
16-
, deleteGroupAvatarGroupId :: UUID
18+
newtype DeleteGroupAvatar = DeleteGroupAvatar {
19+
groupId :: UUID
1720
} deriving (Show)
1821

1922
instance ToJSON DeleteGroupAvatar where
20-
toJSON command = object [
21-
"type" .= deleteGroupAvatarType command
22-
, "groupId" .= deleteGroupAvatarGroupId command]
23-
24-
instance FromJSON DeleteGroupAvatar where
25-
parseJSON (Object o) = DeleteGroupAvatar <$> o .: "type"
26-
<*> o .: "groupId"
23+
toJSON DeleteGroupAvatar {..} =
24+
object ["type" .= ("DeleteGroupAvatar" :: Text), "groupId" .= groupId]
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
13
{-# LANGUAGE OverloadedStrings #-}
2-
module Aitu.Bot.Commands.DeleteMessage (DeleteMessage (..)) where
34

4-
import Data.Aeson
5-
import Data.Text
6-
import Data.Maybe
7-
import Data.UUID.Types
5+
module Aitu.Bot.Commands.DeleteMessage
6+
( DeleteMessage(..)
7+
)
8+
where
89

9-
import Aitu.Bot.Types.Peer (Peer)
10+
import Data.Aeson
11+
import Data.Text
12+
import Data.Maybe
13+
import Data.UUID.Types
14+
15+
import Aitu.Bot.Types.Peer ( Peer )
1016

1117
--
1218
-- doc: https://btsdigital.github.io/bot-api-contract/DeleteMessage.html
1319
data DeleteMessage = DeleteMessage {
14-
deleteMessageType :: Text
15-
, deleteMessageId :: UUID
16-
, deleteMessageDialog :: Peer
20+
messageId :: UUID
21+
, dialog :: Peer
1722
} deriving (Show)
1823

1924
instance ToJSON DeleteMessage where
20-
toJSON command = object [
21-
"type" .= deleteMessageType command
22-
, "messageId" .= deleteMessageId command
23-
, "dialog" .= deleteMessageDialog command]
24-
25-
instance FromJSON DeleteMessage where
26-
parseJSON (Object o) = DeleteMessage <$> o .: "type"
27-
<*> o .: "messageId"
28-
<*> o .: "dialog"
25+
toJSON DeleteMessage {..} = object
26+
[ "type" .= ("DeleteMessage" :: Text)
27+
, "messageId" .= messageId
28+
, "dialog" .= dialog
29+
]
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11

2+
{-# LANGUAGE RecordWildCards #-}
3+
{-# LANGUAGE DuplicateRecordFields #-}
24
{-# LANGUAGE OverloadedStrings #-}
35

4-
module Aitu.Bot.Commands.EditContainerMessage (EditContainerMessage (..)) where
6+
module Aitu.Bot.Commands.EditContainerMessage
7+
( EditContainerMessage(..)
8+
)
9+
where
510

6-
import Data.Aeson
7-
import Data.Text
8-
import Data.Maybe
11+
import Data.Aeson
12+
import Data.Text
13+
import Data.Maybe
914

10-
import Data.UUID.Types
15+
import Data.UUID.Types
1116

12-
import Aitu.Bot.Types.Peer (Peer)
13-
import Aitu.Bot.Types.UIState (UIState)
14-
import Aitu.Bot.Types.InputMedia (InputMedia)
15-
import Aitu.Bot.Types.InlineCommand (InlineCommand, RowInlineCommands)
17+
import Aitu.Bot.Types.Peer ( Peer )
18+
import Aitu.Bot.Types.UIState ( UIState )
19+
import Aitu.Bot.Types.InputMedia ( InputMedia )
20+
import Aitu.Bot.Types.InlineCommand ( InlineCommand
21+
, RowInlineCommands
22+
)
1623

1724
-- doc: https://btsdigital.github.io/bot-api-contract/EditContainerMessage.html
1825
data EditContainerMessage = EditContainerMessage {
19-
editContainerMessageType :: Text
20-
, editContainerMessageRecipient :: Peer
21-
, editContainerMessageContent :: Text
26+
recipient :: Peer
27+
, content :: Text
2228
} deriving (Show)
2329

2430
instance ToJSON EditContainerMessage where
25-
toJSON command = object [
26-
"type" .= editContainerMessageType command
27-
, "recipient" .= editContainerMessageRecipient command
28-
, "content" .= editContainerMessageContent command]
29-
30-
instance FromJSON EditContainerMessage where
31-
parseJSON (Object o) =
32-
EditContainerMessage <$> o .: "type"
33-
<*> o .: "recipient"
34-
<*> o .: "content"
31+
toJSON EditContainerMessage {..} = object
32+
[ "type" .= ("EditContainerMessage" :: Text)
33+
, "recipient" .= recipient
34+
, "content" .= content
35+
]
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
13
{-# LANGUAGE OverloadedStrings #-}
24

35
module Aitu.Bot.Commands.EditMessage
@@ -19,22 +21,20 @@ import Aitu.Bot.Types.InlineCommand ( InlineCommand
1921
-- EditMessageCommand sends message about a message editing
2022
-- docs: https://btsdigital.github.io/bot-api-contract/EditMessage.html
2123
data EditMessage = EditMessage {
22-
editMessageType :: Text
23-
, editMessageId :: Text
24-
, editMessageRecipient :: Peer
25-
, editMessageContent :: Text
26-
, editMessageInlineCommandRows :: Maybe [RowInlineCommands]
27-
, editMessageUIState :: Maybe UIState
28-
, editMessageMediaList :: Maybe [InputMedia]} deriving (Show)
24+
messageId :: Text
25+
, recipient :: Peer
26+
, content :: Text
27+
, inlineCommandRows :: Maybe [RowInlineCommands]
28+
, uiState :: Maybe UIState
29+
, mediaList :: Maybe [InputMedia]} deriving (Show)
2930

3031
instance ToJSON EditMessage where
31-
toJSON command = object
32-
[ "type" .= editMessageType command
33-
, "messageId" .= editMessageId command
34-
, "recipient" .= editMessageRecipient command
35-
, "content" .= editMessageContent command
36-
, "inlineCommandRows"
37-
.= maybeToList (editMessageInlineCommandRows command)
38-
, "uiState" .= editMessageUIState command
39-
, "mediaList" .= maybeToList (editMessageMediaList command)
32+
toJSON EditMessage {..} = object
33+
[ "type" .= ("EditMessage" :: Text)
34+
, "messageId" .= messageId
35+
, "recipient" .= recipient
36+
, "content" .= content
37+
, "inlineCommandRows" .= maybeToList inlineCommandRows
38+
, "uiState" .= uiState
39+
, "mediaList" .= maybeToList mediaList
4040
]
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
13
{-# LANGUAGE OverloadedStrings #-}
24

3-
module Aitu.Bot.Commands.ForwardMessage (ForwardMessage (..)) where
5+
module Aitu.Bot.Commands.ForwardMessage
6+
( ForwardMessage(..)
7+
)
8+
where
49

5-
import Data.Aeson
6-
import Data.Text
7-
import Data.Maybe
8-
import Data.UUID.Types
10+
import Data.Aeson
11+
import Data.Text
12+
import Data.Maybe
13+
import Data.UUID.Types
914

10-
import Aitu.Bot.Types.Peer (Peer)
15+
import Aitu.Bot.Types.Peer ( Peer )
1116

1217
--
1318
-- doc: https://btsdigital.github.io/bot-api-contract/ForwardMessage.html
1419
data ForwardMessage = ForwardMessage {
15-
forwardMessageType :: Text
16-
, forwardMessageLocalId :: Maybe UUID
17-
, forwardMessageFromDialog :: Peer
18-
, forwardMessageToDialog :: Peer
19-
, forwardMessageId :: UUID
20+
localId :: Maybe UUID
21+
, fromDialog :: Peer
22+
, toDialog :: Peer
23+
, messageId :: UUID
2024
} deriving (Show)
2125

2226
instance ToJSON ForwardMessage where
23-
toJSON command = object [
24-
"type" .= forwardMessageType command
25-
, "localId" .= forwardMessageLocalId command
26-
, "fromDialog" .= forwardMessageFromDialog command
27-
, "toDialog" .= forwardMessageToDialog command
28-
, "messageId" .= forwardMessageId command]
29-
30-
instance FromJSON ForwardMessage where
31-
parseJSON (Object o) = ForwardMessage <$> o .: "type"
32-
<*> o .:? "localId"
33-
<*> o .: "fromDialog"
34-
<*> o .: "toDialog"
35-
<*> o .: "messageId"
27+
toJSON ForwardMessage {..} = object
28+
[ "type" .= ("ForwardMessage" :: Text)
29+
, "localId" .= localId
30+
, "fromDialog" .= fromDialog
31+
, "toDialog" .= toDialog
32+
, "messageId" .= messageId
33+
]

0 commit comments

Comments
 (0)