@@ -8,11 +8,12 @@ module Bot.CustomCommand
88 , updateCustomCommand
99 , showCustomCommand
1010 , timesCustomCommand
11- , CustomCommand (.. )
1211 ) where
1312
13+ import Bot.CustomCommandType
1414import Bot.Expr
1515import Bot.Flip
16+ import Bot.Help
1617import Bot.Replies
1718import Command
1819import Control.Monad
@@ -32,35 +33,16 @@ import Reaction
3233import Text.InterpolatedString.QM
3334import Transport
3435
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-
5436customCommandByName :: T. Text -> MaybeT Effect (Entity CustomCommand )
5537customCommandByName name =
5638 MaybeT $
5739 fmap listToMaybe $
5840 selectEntities Proxy $ Filter (PropertyEquals " name" $ PropertyText name) All
5941
60- -- TODO(#815): CRUD custom command should update help page now they're listed there as well.
6142addCustomCommand :: CommandTable -> Reaction Message (T. Text , T. Text )
6243addCustomCommand builtinCommands =
63- Reaction $ \ Message {messageSender = sender, messageContent = (name, message)} -> do
44+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = (name, message)} -> do
45+ runReaction refreshHelpGistId mesg
6446 customCommand <- runMaybeT $ customCommandByName name
6547 let builtinCommand = M. lookup name builtinCommands
6648 case (customCommand, builtinCommand) of
@@ -85,7 +67,8 @@ addCustomCommand builtinCommands =
8567
8668deleteCustomCommand :: CommandTable -> Reaction Message T. Text
8769deleteCustomCommand builtinCommands =
88- Reaction $ \ Message {messageSender = sender, messageContent = name} -> do
70+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = name} -> do
71+ runReaction refreshHelpGistId mesg
8972 customCommand <- runMaybeT $ customCommandByName name
9073 let builtinCommand = M. lookup name builtinCommands
9174 case (customCommand, builtinCommand) of
@@ -155,7 +138,8 @@ timesCustomCommand builtinCommands =
155138
156139updateCustomCommand :: CommandTable -> Reaction Message (T. Text , T. Text )
157140updateCustomCommand builtinCommands =
158- Reaction $ \ Message {messageSender = sender, messageContent = (name, message)} -> do
141+ Reaction $ \ mesg@ Message {messageSender = sender, messageContent = (name, message)} -> do
142+ runReaction refreshHelpGistId mesg
159143 customCommand <- runMaybeT $ customCommandByName name
160144 let builtinCommand = M. lookup name builtinCommands
161145 case (customCommand, builtinCommand) of
0 commit comments