Skip to content

Commit 8a1e4dd

Browse files
authored
Merge pull request #814 from jappeace/649-custom-commands
649 custom commands in help page
2 parents 0587308 + e7cd401 commit 8a1e4dd

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/Bot/CustomCommand.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Bot.CustomCommand
88
, updateCustomCommand
99
, showCustomCommand
1010
, timesCustomCommand
11+
, CustomCommand(..)
1112
) where
1213

1314
import Bot.Expr
@@ -55,6 +56,7 @@ customCommandByName name =
5556
fmap listToMaybe $
5657
selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All
5758

59+
-- TODO(#815): CRUD custom command should update help page now they're listed there as well.
5860
addCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text)
5961
addCustomCommand builtinCommands =
6062
Reaction $ \Message {messageSender = sender, messageContent = (name, message)} -> do

src/Bot/Help.hs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Bot.Help
88
, startRefreshHelpGistTimer
99
) where
1010

11+
import Bot.CustomCommand
1112
import Bot.GitHub
1213
import Bot.Replies
1314
import Command
@@ -71,18 +72,39 @@ refreshHelpGistId =
7172
cmapR (const "Scheduled to refresh the Help Gist Page") $
7273
Reaction replyMessage
7374

74-
gistRenderBuiltinCommand :: (T.Text, BuiltinCommand) -> T.Text
75-
gistRenderBuiltinCommand (name, command) =
76-
[qms||{name}|{bcDescription command}|{bcGitHubLocation command}||]
77-
7875
gistRenderCommandTable :: CommandTable -> T.Text
79-
gistRenderCommandTable = T.unlines . map gistRenderBuiltinCommand . M.toList
76+
gistRenderCommandTable =
77+
([qms|* Builtin Commands\n{header}\n|-\n|] <>) .
78+
T.unlines . map renderRow . M.toList
79+
where
80+
header :: T.Text
81+
header = "|Name|Description|Location|"
82+
renderRow :: (T.Text, BuiltinCommand) -> T.Text
83+
renderRow (name, command) =
84+
[qms||{name}|{bcDescription command}|{location}||]
85+
where
86+
location :: T.Text
87+
location = [qms|[[{bcGitHubLocation command}][Source↗]]|]
88+
89+
gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text
90+
gistRenderCustomCommandsTable =
91+
([qms|* Custom commands\n{header}\n|-\n|] <>) .
92+
T.unlines . map (renderRow . entityPayload)
93+
where
94+
header :: T.Text
95+
header = "|Name|Definition|%times|"
96+
renderRow (CustomCommand name message times) =
97+
[qms||{name}|{message}|{times}||]
8098

81-
-- TODO(#649): Help Gist Page does not include CustomCommands
8299
refreshHelpGist :: CommandTable -> GistId -> Effect ()
83100
refreshHelpGist commandTable gistId = do
84-
let gistText = gistRenderCommandTable commandTable
85-
updateGistFile helpGistFileName (FileContent gistText) gistId
101+
customsList <- selectEntities Proxy All
102+
updateGistFile
103+
helpGistFileName
104+
(FileContent
105+
(gistRenderCommandTable commandTable <> "\n" <>
106+
gistRenderCustomCommandsTable customsList))
107+
gistId
86108

87109
startRefreshHelpGistTimer :: CommandTable -> Effect ()
88110
startRefreshHelpGistTimer commandTable =

0 commit comments

Comments
 (0)