-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCustomCommandType.hs
More file actions
33 lines (29 loc) · 1.01 KB
/
CustomCommandType.hs
File metadata and controls
33 lines (29 loc) · 1.01 KB
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
{-# LANGUAGE OverloadedStrings #-}
-- | Moved out of CustomCommand to break dependency cycle:
-- Help depends on this type, but custom commands needs
-- to refresh Help and therefore also this type.
module Bot.CustomCommandType
( CustomCommand(..)
) where
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Text as T
import Entity
import Property
data CustomCommand = CustomCommand
{ customCommandName :: T.Text
, customCommandMessage :: T.Text
, customCommandTimes :: Int
}
instance IsEntity CustomCommand where
nameOfEntity _ = "CustomCommand"
toProperties customCommand =
M.fromList
[ ("name", PropertyText $ customCommandName customCommand)
, ("message", PropertyText $ customCommandMessage customCommand)
, ("times", PropertyInt $ customCommandTimes customCommand)
]
fromProperties properties =
CustomCommand <$> extractProperty "name" properties <*>
extractProperty "message" properties <*>
pure (fromMaybe 0 $ extractProperty "times" properties)