Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Bot/CustomCommand.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Bot.CustomCommand
, updateCustomCommand
, showCustomCommand
, timesCustomCommand
, CustomCommand(..)
) where

import Bot.Expr
Expand Down Expand Up @@ -55,6 +56,7 @@ customCommandByName name =
fmap listToMaybe $
selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All

-- TODO(#815): CRUD custom command should update help page now they're listed there as well.
addCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text)
addCustomCommand builtinCommands =
Reaction $ \Message {messageSender = sender, messageContent = (name, message)} -> do
Expand Down
38 changes: 30 additions & 8 deletions src/Bot/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Bot.Help
, startRefreshHelpGistTimer
) where

import Bot.CustomCommand
import Bot.GitHub
import Bot.Replies
import Command
Expand Down Expand Up @@ -71,18 +72,39 @@ refreshHelpGistId =
cmapR (const "Scheduled to refresh the Help Gist Page") $
Reaction replyMessage

gistRenderBuiltinCommand :: (T.Text, BuiltinCommand) -> T.Text
gistRenderBuiltinCommand (name, command) =
[qms||{name}|{bcDescription command}|{bcGitHubLocation command}||]

gistRenderCommandTable :: CommandTable -> T.Text
gistRenderCommandTable = T.unlines . map gistRenderBuiltinCommand . M.toList
gistRenderCommandTable =
([qms|* Builtin Commands\n{header}\n|-\n|] <>) .
T.unlines . map renderRow . M.toList
where
header :: T.Text
header = "|Name|Description|Location|"
renderRow :: (T.Text, BuiltinCommand) -> T.Text
renderRow (name, command) =
[qms||{name}|{bcDescription command}|{location}||]
where
location :: T.Text
location = [qms|[[{bcGitHubLocation command}][Source↗]]|]

gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text
gistRenderCustomCommandsTable =
([qms|* Custom commands\n{header}\n|-\n|] <>) .
T.unlines . map (renderRow . entityPayload)
where
header :: T.Text
header = "|Name|Definition|%times|"
renderRow (CustomCommand name message times) =
[qms||{name}|{message}|{times}||]

-- TODO(#649): Help Gist Page does not include CustomCommands
refreshHelpGist :: CommandTable -> GistId -> Effect ()
refreshHelpGist commandTable gistId = do
let gistText = gistRenderCommandTable commandTable
updateGistFile helpGistFileName (FileContent gistText) gistId
customsList <- selectEntities Proxy All
updateGistFile
helpGistFileName
(FileContent
(gistRenderCommandTable commandTable <> "\n" <>
gistRenderCustomCommandsTable customsList))
gistId

startRefreshHelpGistTimer :: CommandTable -> Effect ()
startRefreshHelpGistTimer commandTable =
Expand Down