diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index f190f63..4adb912 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -8,6 +8,7 @@ module Bot.CustomCommand , updateCustomCommand , showCustomCommand , timesCustomCommand + , CustomCommand(..) ) where import Bot.Expr @@ -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 diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index 570270d..be9e799 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -8,6 +8,7 @@ module Bot.Help , startRefreshHelpGistTimer ) where +import Bot.CustomCommand import Bot.GitHub import Bot.Replies import Command @@ -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 =