@@ -8,11 +8,12 @@ module Bot.CustomCommand
8
8
, updateCustomCommand
9
9
, showCustomCommand
10
10
, timesCustomCommand
11
- , CustomCommand (.. )
12
11
) where
13
12
13
+ import Bot.CustomCommandType
14
14
import Bot.Expr
15
15
import Bot.Flip
16
+ import Bot.Help
16
17
import Bot.Replies
17
18
import Command
18
19
import Control.Monad
@@ -32,35 +33,16 @@ import Reaction
32
33
import Text.InterpolatedString.QM
33
34
import Transport
34
35
35
- data CustomCommand = CustomCommand
36
- { customCommandName :: T. Text
37
- , customCommandMessage :: T. Text
38
- , customCommandTimes :: Int
39
- }
40
-
41
- instance IsEntity CustomCommand where
42
- nameOfEntity _ = " CustomCommand"
43
- toProperties customCommand =
44
- M. fromList
45
- [ (" name" , PropertyText $ customCommandName customCommand)
46
- , (" message" , PropertyText $ customCommandMessage customCommand)
47
- , (" times" , PropertyInt $ customCommandTimes customCommand)
48
- ]
49
- fromProperties properties =
50
- CustomCommand <$> extractProperty " name" properties <*>
51
- extractProperty " message" properties <*>
52
- pure (fromMaybe 0 $ extractProperty " times" properties)
53
-
54
36
customCommandByName :: T. Text -> MaybeT Effect (Entity CustomCommand )
55
37
customCommandByName name =
56
38
MaybeT $
57
39
fmap listToMaybe $
58
40
selectEntities Proxy $ Filter (PropertyEquals " name" $ PropertyText name) All
59
41
60
- -- TODO(#815): CRUD custom command should update help page now they're listed there as well.
61
42
addCustomCommand :: CommandTable -> Reaction Message (T. Text , T. Text )
62
43
addCustomCommand builtinCommands =
63
- Reaction $ \ Message {messageSender = sender, messageContent = (name, message)} -> do
44
+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = (name, message)} -> do
45
+ runReaction refreshHelpGistId mesg
64
46
customCommand <- runMaybeT $ customCommandByName name
65
47
let builtinCommand = M. lookup name builtinCommands
66
48
case (customCommand, builtinCommand) of
@@ -85,7 +67,8 @@ addCustomCommand builtinCommands =
85
67
86
68
deleteCustomCommand :: CommandTable -> Reaction Message T. Text
87
69
deleteCustomCommand builtinCommands =
88
- Reaction $ \ Message {messageSender = sender, messageContent = name} -> do
70
+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = name} -> do
71
+ runReaction refreshHelpGistId mesg
89
72
customCommand <- runMaybeT $ customCommandByName name
90
73
let builtinCommand = M. lookup name builtinCommands
91
74
case (customCommand, builtinCommand) of
@@ -155,7 +138,8 @@ timesCustomCommand builtinCommands =
155
138
156
139
updateCustomCommand :: CommandTable -> Reaction Message (T. Text , T. Text )
157
140
updateCustomCommand builtinCommands =
158
- Reaction $ \ Message {messageSender = sender, messageContent = (name, message)} -> do
141
+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = (name, message)} -> do
142
+ runReaction refreshHelpGistId mesg
159
143
customCommand <- runMaybeT $ customCommandByName name
160
144
let builtinCommand = M. lookup name builtinCommands
161
145
case (customCommand, builtinCommand) of
0 commit comments