From c79ec05c16824bcf80fca1c47f76320914952599 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Mon, 11 Nov 2019 18:45:59 +0100 Subject: [PATCH 1/8] (#649) Add custom commands to the help page --- src/Bot/CustomCommand.hs | 1 + src/Bot/Help.hs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index f190f63..3b7fff0 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 diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index 570270d..23d506e 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -8,6 +8,8 @@ module Bot.Help , startRefreshHelpGistTimer ) where +import Data.Proxy +import Bot.CustomCommand import Bot.GitHub import Bot.Replies import Command @@ -15,7 +17,6 @@ import Data.Bool.Extra import Data.Functor import qualified Data.Map as M import Data.Maybe -import Data.Proxy import qualified Data.Text as T import Effect import Entity @@ -75,14 +76,28 @@ gistRenderBuiltinCommand :: (T.Text, BuiltinCommand) -> T.Text gistRenderBuiltinCommand (name, command) = [qms||{name}|{bcDescription command}|{bcGitHubLocation command}||] +gistRenderCustomCommand :: CustomCommand -> T.Text +gistRenderCustomCommand (CustomCommand name message times) = + [qms||{name}|{message}|{times}||] + gistRenderCommandTable :: CommandTable -> T.Text -gistRenderCommandTable = T.unlines . map gistRenderBuiltinCommand . M.toList +gistRenderCommandTable = ("* Builtin Commands \n" <>) . + T.unlines . map gistRenderBuiltinCommand . M.toList -- 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 <- getCustomCommands + let customCommands = T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList + updateGistFile + helpGistFileName + (FileContent (gistText <> "\n* Custom commands \n" <> customCommands)) + gistId + where + gistText = gistRenderCommandTable commandTable + +getCustomCommands :: Effect ([Entity CustomCommand]) +getCustomCommands = selectEntities Proxy All startRefreshHelpGistTimer :: CommandTable -> Effect () startRefreshHelpGistTimer commandTable = From 3d5d00470881078e1c3dc023c07c9959ad1dbb6d Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Mon, 11 Nov 2019 18:56:19 +0100 Subject: [PATCH 2/8] Documented a todo item for future work --- src/Bot/CustomCommand.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index 3b7fff0..de3c404 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -56,6 +56,7 @@ customCommandByName name = fmap listToMaybe $ selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All +-- TODO: Add 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 From 024623446edac8e7ee51ad39153ff35f587b765c Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Mon, 11 Nov 2019 18:56:38 +0100 Subject: [PATCH 3/8] Better description of the todo item --- src/Bot/CustomCommand.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index de3c404..61807f0 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -56,7 +56,7 @@ customCommandByName name = fmap listToMaybe $ selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All --- TODO: Add custom command should update help page now they're listed there as well. +-- TODO: 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 From 0882747cca0f9ae54c1c0e13a6f011498b4690b7 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Mon, 11 Nov 2019 18:58:30 +0100 Subject: [PATCH 4/8] Execute Hlint and Hindent --- src/Bot/Help.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index 23d506e..4de3770 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -8,7 +8,6 @@ module Bot.Help , startRefreshHelpGistTimer ) where -import Data.Proxy import Bot.CustomCommand import Bot.GitHub import Bot.Replies @@ -17,6 +16,7 @@ import Data.Bool.Extra import Data.Functor import qualified Data.Map as M import Data.Maybe +import Data.Proxy import qualified Data.Text as T import Effect import Entity @@ -25,10 +25,11 @@ import Reaction import Text.InterpolatedString.QM import Transport -data HelpState = HelpState - { helpStateGistId :: Maybe GistId - , helpStateGistFresh :: Bool - } +data HelpState = + HelpState + { helpStateGistId :: Maybe GistId + , helpStateGistFresh :: Bool + } updateHelpStateGistId :: GistId -> HelpState -> HelpState updateHelpStateGistId (GistId "") state = state {helpStateGistId = Nothing} @@ -81,22 +82,24 @@ gistRenderCustomCommand (CustomCommand name message times) = [qms||{name}|{message}|{times}||] gistRenderCommandTable :: CommandTable -> T.Text -gistRenderCommandTable = ("* Builtin Commands \n" <>) . +gistRenderCommandTable = + ("* Builtin Commands \n" <>) . T.unlines . map gistRenderBuiltinCommand . M.toList -- TODO(#649): Help Gist Page does not include CustomCommands refreshHelpGist :: CommandTable -> GistId -> Effect () refreshHelpGist commandTable gistId = do customsList <- getCustomCommands - let customCommands = T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList + let customCommands = + T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList updateGistFile helpGistFileName (FileContent (gistText <> "\n* Custom commands \n" <> customCommands)) gistId - where - gistText = gistRenderCommandTable commandTable + where + gistText = gistRenderCommandTable commandTable -getCustomCommands :: Effect ([Entity CustomCommand]) +getCustomCommands :: Effect [Entity CustomCommand] getCustomCommands = selectEntities Proxy All startRefreshHelpGistTimer :: CommandTable -> Effect () From 48ab16751a0f9632017a80ac13973341adc7ed7c Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Tue, 12 Nov 2019 10:08:47 +0100 Subject: [PATCH 5/8] Hindent help --- src/Bot/Help.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index 4de3770..e5f72b9 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -25,11 +25,10 @@ import Reaction import Text.InterpolatedString.QM import Transport -data HelpState = - HelpState - { helpStateGistId :: Maybe GistId - , helpStateGistFresh :: Bool - } +data HelpState = HelpState + { helpStateGistId :: Maybe GistId + , helpStateGistFresh :: Bool + } updateHelpStateGistId :: GistId -> HelpState -> HelpState updateHelpStateGistId (GistId "") state = state {helpStateGistId = Nothing} From 48e68175b7cf8c5ca50e8910a383b600f5663320 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 15 Nov 2019 00:04:17 +0700 Subject: [PATCH 6/8] (#649) Restructure the table rendering code --- src/Bot/Help.hs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index e5f72b9..b6dbca6 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -72,34 +72,29 @@ 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}||] - -gistRenderCustomCommand :: CustomCommand -> T.Text -gistRenderCustomCommand (CustomCommand name message times) = - [qms||{name}|{message}|{times}||] - gistRenderCommandTable :: CommandTable -> T.Text gistRenderCommandTable = - ("* Builtin Commands \n" <>) . - T.unlines . map gistRenderBuiltinCommand . M.toList + ("* Builtin Commands \n" <>) . T.unlines . map renderRow . M.toList + where + renderRow (name, command) = + [qms||{name}|{bcDescription command}|{bcGitHubLocation command}||] + +gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text +gistRenderCustomCommandsTable = + ("* Custom commands \n" <>) . T.unlines . map (renderRow . entityPayload) + where + 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 - customsList <- getCustomCommands - let customCommands = - T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList + customsList <- selectEntities Proxy All updateGistFile helpGistFileName - (FileContent (gistText <> "\n* Custom commands \n" <> customCommands)) + (FileContent + (gistRenderCommandTable commandTable <> "\n" <> + gistRenderCustomCommandsTable customsList)) gistId - where - gistText = gistRenderCommandTable commandTable - -getCustomCommands :: Effect [Entity CustomCommand] -getCustomCommands = selectEntities Proxy All startRefreshHelpGistTimer :: CommandTable -> Effect () startRefreshHelpGistTimer commandTable = From 62598112a75d650dde5ffc37411d3ea6e70603cc Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 15 Nov 2019 00:37:44 +0700 Subject: [PATCH 7/8] (#649) Enhance the rendering of the table --- src/Bot/Help.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index b6dbca6..be9e799 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -74,15 +74,25 @@ refreshHelpGistId = gistRenderCommandTable :: CommandTable -> T.Text gistRenderCommandTable = - ("* Builtin Commands \n" <>) . T.unlines . map renderRow . M.toList + ([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}|{bcGitHubLocation command}||] + [qms||{name}|{bcDescription command}|{location}||] + where + location :: T.Text + location = [qms|[[{bcGitHubLocation command}][Source↗]]|] gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text gistRenderCustomCommandsTable = - ("* Custom commands \n" <>) . T.unlines . map (renderRow . entityPayload) + ([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}||] From e7cd401d50c58fbbf10f95e3ef6c19bbc53e4201 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 15 Nov 2019 00:52:21 +0700 Subject: [PATCH 8/8] Add TODO(#815) --- src/Bot/CustomCommand.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index 61807f0..4adb912 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -56,7 +56,7 @@ customCommandByName name = fmap listToMaybe $ selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All --- TODO: CRUD custom command should update help page now they're listed there as well. +-- 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